我一直搞不懂這里面的循環是怎么回事
public static void main(String[] args) {
??int[] a=new int[]{20,10,50,40,30,70,60,80,90,100};
?? for(int i=0;i<10;i++)
???????????? for(int j=0;j<a.length-i-1;j++)
???????????????? if(a[j]>a[j+1]){
???????????????????? int temp = a[j];
???????????????????? a[j] = a[j+1];
???????????????????? a[j+1] = temp;
???????????????? }
???????? for(int i=0;i<a.length;i++)
?????????? System.out.print(a[i]+" ");
?}
}
2018-11-18
為什么不能直接用a[i],你可以發現在a[i+1]之后是可以取10的。還有,像這種多重循環結構,一般第一條循環語句是用來”定位“的
2018-11-07
這是冒泡吧,你畫個圖就明白了
2018-11-01
表示兩個相鄰的數比較