public class Paixu {
public static void main(String[] args)
{
paixu();
}
public static void paixu(){
int [] a =
{23,12,15,2,4,10};
for(int i = 0;i<a.length-1;i++){
//此处做优化减去i
for(int j = 0;j<a.length-i-1;j++){
//将比较完的2个值进行交换
if(a[j]>a[j+1]){
int t =
a[j];
a[j]=a[j+1];
a[j+1]=t;
}
}
}
for(int
m=0;m<a.length-1;m++){
System.out.println(a[m]);
}
}
}
原文:http://www.cnblogs.com/hugo-guo/p/3737610.html