package com.bjpowernode.t01;
/*
 * 冒泡排序
 */
public class TestArray {
	public static void main(String[] args) {
		int[] a = {4,2,7,3,6};
		
		//外层for循环控制比较的轮数
		for(int i=a.length-1; i>0; i--) {
			//内层循环控制比较的次数
			for(int j=0; j<i; 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.println(a[i]);
		}
	}
}
原文:https://www.cnblogs.com/Koma-vv/p/9543680.html