package select; public class Select { //交换 void Swap(int a[],int x,int y){ int temp = a[x]; a[x] = a[y]; a[y] = temp; } //打印出 void Print(int a[]){ for(int x: a){ System.out.print(x); } } public void SelectSort(int a[]) { for(int i=0;i<a.length-1;i++){ int min = i; for(int j=i+1;j<a.length;j++){ if(a[min]>a[j]){ min = j; } } if(min!=i){ Swap(a, min, i); } } Print(a); } } //test package test; import select.Select; public class Test { public static void main(String[] args) { int []array ={9,1,5,8,3,7,4,6,2}; Select sort = new Select(); sort.SelectSort(array); } }