冒泡排序法

从大到小排序:

package com.jike.array;

public class test04 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		/*
		 * 冒泡排序
		 */
		int score[]= {10,50,30,90,70};
		for (int i = 0; i < score.length-1; i++) {
			for (int j = i+1; j < score.length; j++) {
				if(score[i]<score[j]) {
					int tem=score[i];
					score[i]=score[j];
					score[j]=tem;
				}
			}
			System.out.print("第"+(i+1)+"次排序:");
			for (int j = 0; j < score.length; j++) {
				System.out.print(score[j]+"	");
			}
			System.out.println("");
		}
		for (int i = 0; i < score.length; i++) {
			System.out.println(score[i]);
		}
	}
}

 输出:

第1次排序:90	10	30	50	70	
第2次排序:90	70	10	30	50	
第3次排序:90	70	50	10	30	
第4次排序:90	70	50	30	10	
90
70
50
30
10
原文地址:https://www.cnblogs.com/zhhy236400/p/10435639.html