Simple selection and sorting
1 package com. hp. io; 2 3 import java. util. secret; 4 5 public class XuanZe {6 public static void main (String [] args) {7 seconds s = new second (System. in); 8 System. out. println ("Enter the number of arrays"); 9 int a = s. nextInt (); 10 int [] B = new int [a]; 11 System. out. println ("elements in the input array:"); 12 for (int I = 0; I <B. length; I ++) {// the elements in the array need to traverse 13 B [I] = s. nextInt (); 14} 15 for (int I = 0; I <B. length-1; I ++) {16 for (int j = I + 1; j <B. length; j ++) {17 if (B [I]> B [j]) {18 int temp = B [I]; 19 B [I] = B [j]; 20 B [j] = temp; 21} 22} 23} 24 for (int k = 0; k <B. length; k ++) {25 System. out. println (B [k] + ""); 26} 27} 28}
1 package com. hp. io; 2 3 import java. util. secret; 4 5 public class MaoPao {6 public static void main (String [] args) {7 s = new second (System. in); 8 System. out. println ("Enter the number of arrays"); 9 int a = s. nextInt (); 10 int [] B = new int [a]; 11 System. out. println ("elements in the input array:"); // traverses the elements in the array 12 for (int I = 0; I <B. length; I ++) {13 B [I] = s. nextInt (); // the element of array B is the input element 14} 15 for (int I = 0; I <B. length-1; I ++) {16 for (int j = I + 1; j <B. length; j ++) {17 if (B [I]> B [j]) {18 int temp = B [I]; 19 B [I] = B [j]; 20 B [j] = temp; 21} 22} 23} 24 for (int k = 0; k <B. length; k ++) {// when printing, the array is also required to traverse 25 System. out. println (B [k] + ""); 26} 27}