Program for selection sort
Answers
here is your answer
see the attached file ⬆⬆⬆
glad to help you
hope it helps
thank you
import java.util.*;
class selection_sort
{
public void main()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number of elements in an array");
int n=sc.nextInt();
int a[]=new int[n];
System.out.println("Enter the array values randomly ! I will sort it ! I know magic");
for(int i=0;i<n;i++)
{
a[i]=sc.nextInt();
}
int min=0;
int temp=0;
for(int i=0;i<(n-1);i++)
{
min=i;
for(int j=i+1;j<n;j++)
{
if(a[j]<a[min])
{
min=j;
}
}
temp=a[i];
a[i]=a[min];
a[min]=temp;
}
System.out.println("Sorted array in ascending order gives all negative first then positive hehe");
for(int i=0;i<n;i++)
{
System.out.println(a[i]);
}
}
}