1 Packagelog;2 3 Public classTest4 {4 5 /**6 * Java Algorithm---Select Sort7 * 8 * @paramargs9 */Ten Public Static voidMain (string[] args) { One //arrays that need to be sorted A intArr[] = {49, 20, 36, 51, 18, 94, 61, 31, 50 }; - //loop out the contents of the array -System.out.println ("Before sorting:"); the for(intA:arr) { -System.out.print (A + "\ T")); - } - System.out.println (); + - intPosition = 0; + for(inti = 0; i < arr.length; i++) { A intj = i + 1; atPosition =i; - inttemp =Arr[i]; - for(; J < Arr.length; J + +) { - if(Arr[j] <temp) { -temp =Arr[j]; -Position =J; in } - } toArr[position] =Arr[i]; +Arr[i] =temp; - } the //loop out the contents of the array *System.out.println ("After sorting:"); $ for(intA:arr) {Panax NotoginsengSystem.out.print (A + "\ T")); - } the System.out.println (); + A } the +}
Here's the console output.
Java algorithm----Sort----(2) Select sort