java冒泡排序

public class ArrayDemo {
public static void main(String[] args) {
int array[] =new int[10];
int tmp;
for (int i = 0; i <10 ; i++) {
array[i]=(int)(Math.random()*100);
System.out.println(array[i]+"、");
}
System.out.println();
for (int a = 0; a <10 ; a++) {
for (int j = 0; j <a ; j++) {
if(array[j]>array[j+1]){
tmp=array[j];
array[j]=array[j+1];
array[j+1]=tmp;

}

}
}
for (int i = 0; i <10 ; i++) {
System.out.println(array[i]+" ");
}
}
结果:

6
10
17
33
48
53
77
81
15
96



posted @ 2020-05-31 17:25  zhaoxilai  阅读(110)  评论(0编辑  收藏  举报