选择排序
public class TestArray { public static void main(String[] args) { int[] a = new int [args.length]; for( int i=0;i<a.length; i++ ) { a[i] = Integer.parseInt(args[i]); } print(a); selectionSort(a); print(a); } //排序从小到大 private static void selectionSort(int[] a) { int k,temp; for(int i = 0;i<a.length;i++) { k = i; for(int j=k+1;j<a.length;j++ ) { if(a[j] < a[k]) { k = j; } } if(k!=i) { temp = a[i]; a[i] = a[k]; a[k] = temp; } } } //打印出输入的数字 private static void print(int[] a) { for(int i = 0;i<a.length;i++) { System.out.print(a[i]+" "); } System.out.println(); } }