将老师所讲进行整理
1 System.out.println("原始顺序:"); 2 int []sa = new int[]{49,38,98,54,76,13,27,1}; 3 for(int t:sa) 4 { 5 System.out.print(t+" "); 6 } 7 System.out.println(); 8 int m=0; 9 for(int j=0;jsa[i+1])//比较前后元素的大小顺序14 { 15 int b=sa[i];//临时存放16 sa[i]=sa[i+1];17 sa[i+1]=b;18 }19 m++;20 }21 System.out.println((j+1)+"次循环:"); //j+1是因为数组默认是从0开始22 for(int t:sa)23 {24 System.out.print(t+" ");25 } 26 System.out.println(); 27 }28 System.out.println("共"+m+"次循环");
运算结果为: