Java implementation code that sorts 10 Numbers
- 2020-06-15 08:26:22
- OfStack
Title: Sort 10 Numbers
Program analysis: selection method can be used, that is, from the latter 9 comparison process, select the smallest element and the first element exchange, next analogy, that is, the second element and the latter 8 for comparison, and exchange.
Program design:
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;
public class Ex28 {
public static void main(String[] args) {
int arr[] = new int[11];
Random r=new Random();
for(int i=0;i<10;i++){
arr[i]=r.nextInt(100)+1;// get 10 a 100 Integer within
}
Arrays.sort(arr);
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+"\t");
}
System.out.print("\nPlease Input a int number: ");
Scanner sc=new Scanner(System.in);
arr[10]=sc.nextInt();// The input 1 a int value
Arrays.sort(arr);
for(int i=0;i<arr.length;i++){
System.out.print(arr[i]+"\t");
}
}
}