Write a java program to input 10 elements in a single dimensional array and sort them in ascending order using Selection Sort.
Only quality answers required. Compile the program and show the output.
Answers
Answer:
The given cσde is written in Java.
import java.util.*;
public class Selection_Sort {
public static void main(String args[]) {
Scanner sc=new Scanner(System.in);
System.out.println("Enter 10 elements...");
int a[]=new int[10],i,j,x;
for(i=0;i<10;i++) {
System.out.print(">> ");
a[i]=sc.nextInt();
}
System.out.println("Given Array: "+Arrays.toString(a));
for(i=0;i<10;i++) {
for(j=i+1;j<10;j++) {
if(a[i]>a[j]) {
x=a[i];
a[i]=a[j];
a[j]=x;
}
}
}
System.out.println("Sorted Array: "+Arrays.toString(a));
sc.close();
}
}
See the attachment for output.
•••♪