1 public class Paixu { 2 public static void main(String args[]) { 3 int myNum[] = {2,6,4,1,5}; 4 //从小到大排序: 5 int tempNum=0; 6 for(int i=0;i<5;i++) { 7 for (int j=i+1;j<5;j++) { 8 if(myNum[i]>myNum[j]) { 9 tempNum=myNum[i]; 10 myNum[i]=myNum[j]; 11 myNum[j]=tempNum; 12 } 13 } 14 } 15 for(int a:myNum) { 16 System.out.println(a); 17 } 18 } 19 }