闲来无事,日常冒泡

 public class BubbleSort {
 2      public static void main(String[] args){
 3                    int score[] = {60,80,75,65,89,90,100,59};
 4                    for (int i=0; i<score.length-1;i++){         //外层控制排序趟数,最多做n-1趟排序
 5                        for(int j=0;j<score.length-i-1;j++){    //内层循环控制每一趟排序多少次
 6                            if(score[j+1] < score[j]){        //把小的值交换到前面
 7                                int temp = score[j];
 8                                score[j] = score[j + 1];
 9                                score[j + 1] = temp;
10                           }
11                       }            
12                       System.out.print("第" + (i + 1) + "次排序结果:");
13                       for(int a = 0; a < score.length; a++){
14                           System.out.print(score[a] + "	");
15                       }
16                       System.out.println("");
17                   }
18                       System.out.print("最终排序结果:");
19                       for(int a = 0; a < score.length; a++){
20                          System.out.print(score[a] + "	");
21                 }
22              }
23     }

  

原文地址:https://www.cnblogs.com/DIVEY/p/10682798.html