Write a JAVA program to input 15 numbers in array and sort it by using Selection sorting
technique.
Answers
Answered by
3
Answer:
import java.util.*;
public class Main
{
public static void main(String args[ ])
{
Scanner in=new Scanner(System.in);
int a[]=new int[15];
int temp,min=0;
System.out.println("Enter the elememnts of the array");
for(int i=0;i<a.length;i++)
{
a[i]=in.nextInt();
}
System.out.println("Given Array:"+Arrays.toString(a));
for(int i=0;i<a.length;i++)
{
min=i;
for(int j=i+1;j<a.length;j++)
{
if(a[j]<a[min])
min=j;
}
temp=a[i];
a[i]=a[min];
a[min]=temp;
}
System.out.println("Sorted Array:"+Arrays.toString(a));
}
}
Refer to the attachment for the output:-
- The first photo is the half photo
- The second photo is the second half photo
Attachments:
Similar questions