package com.algorithm; /** * @Description 冒泡 * @author FuJianyong * 2015-1-22上午09:58:39 */ public class MaoPao { public static void main(String[] args) { int[] mao = {17,50,26,18,9,100,88};//静态分配数组初始数值 int temp = 0; //外部循环执行遍历冒泡 for(int i=0;i<mao.length;i++) { //内部循环执行相邻两个数组比较,大的就冒泡 for(int j=0;j<mao.length-1;j++) { //如果左边的数组大于右边的数组 if(mao[j]>mao[j+1]) { temp = mao[j+1];//右边的数组赋值给临时对象 mao[j+1] = mao[j];//左边的数组赋值给右边的数组 mao[j] = temp;//临时对象赋值给左边的数组 } } } for(int i=0;i<mao.length;i++) { System.out.print(" "+mao[i]); } } }