1 PackageCom.hp.io;2 3 ImportJava.util.Scanner;4 5 Public classXuanze {6 Public Static voidMain (string[] args) {7Scanner s =NewScanner (system.in);8System.out.println ("Please enter the number of arrays");9 intA =s.nextint ();Ten int[] B =New int[a]; OneSystem.out.println ("Elements in the input array:"); A for(inti = 0; i < b.length; i++{//The elements in the array are traversed after the operation -B[i] =s.nextint (); - } the for(inti = 0; i < b.length-1; i++) { - for(intj = i + 1; J < B.length; J + +) { - if(B[i] >B[j]) { - inttemp =B[i]; +B[i] =B[j]; -B[J] =temp; + } A } at } - for(intk = 0; K < B.length; k++) { -System.out.println (B[k] + ""); - } - } -}
1 PackageCom.hp.io;2 3 ImportJava.util.Scanner;4 5 Public classMaopao {6 Public Static voidMain (string[] args) {7Scanner s =NewScanner (system.in);8System.out.println ("Please enter the number of arrays");9 intA =s.nextint ();Ten int[] B =New int[a]; OneSystem.out.println ("Elements in the input array:");//traversing elements in an array A for(inti = 0; i < b.length; i++) { -B[i] = S.nextint ();//the element of array B is the element of the input - } the for(inti = 0; i < b.length-1; i++) { - for(intj = i + 1; J < B.length; J + +) { - if(B[i] >B[j]) { - inttemp =B[i]; +B[i] =B[j]; -B[J] =temp; + } A } at } - for(intk = 0; K < B.length; k++) {//The array is also required to traverse when printing -System.out.println (B[k] + ""); - } - }
Simple sort of selection