package com.zsh;
public class Test {
public static void main(String[] args){
int score[] = {67, 69, 75, 87, 89, 90, 99, 100};
for (int i = 0; i < score.length -1; i++){ //最多做n-1趟排序
for(int j = 0 ;j < score.length - i - 1; j++){ //對當(dāng)前無序區(qū)間score[0......length-i-1]進(jìn)行排序(j的范圍很關(guān)鍵,這個范圍是在逐步縮小的)
if(score[j] < score[j + 1]){ //把小的值交換到后面
int temp = score[j];
score[j] = score[j + 1];
score[j + 1] = temp;
}
}
System.out.print("第" + (i + 1) + "次排序結(jié)果:");
for(int a = 0; a < score.length; a++){
System.out.print(score[a] + "\t");
}
System.out.println("");
}
System.out.print("最終排序結(jié)果:");
for(int a = 0; a < score.length; a++){
System.out.print(score[a] + "\t");
}
}
}
冒泡排序輸出結(jié)果