public class BubbleSort {
public static void main(String[] args) {
int score[] = {1,4,5,7,2,3,9,0,6,8};
for(int i=1;i<score.length;i++){ //最多做n-1趟排序
for(int j=0;j<score.length-i;j++){ //每次排序范围减少
if(score[j]<score[j+1]){
//交行2个变量数据的3种方法
// int temp = score[j];
// score[j] = score[j+1];
// score[j+1] = temp;
score[j] = score[j]^score[j+1];
score[j+1] = score[j]^score[j+1];
score[j] = score[j]^score[j+1];
// score[j] = score[j]+score[j+1];
// score[j+1] = score[j]-score[j+1];
// score[j] = score[j]-score[j+1];
}
}
System.out.print("第" + i + "次排序结果:");
for(int a=0;a<score.length;a++){
System.out.print(score[a]+"\t");
}
System.out.println("");
}
System.out.print("最终0排序结果:");
for(int a=0;a<score.length;a++){
System.out.print(score[a]+"\t");
}
}
}