public class SortList {
public static void main(String[] args) {
int[] array = {66,88,1,35,879,0};
//外层遍历到 集合倒数第二个数据
for(int i=0; i<array.length-1 ;i++){
//内层每轮循环会找出一个最大的数, 所以内层循环每轮少遍历一个
for(int j=0; j<array.length-i-1; j++){
int next = array[j+1];
int now = array[j];
if (now > next){
//换位
array[j] = next;
array[j+1] = now;
}
}
}
//输出数组
for(int i=0; i<array.length; i++){
System.out.print(array[i]+",");
}
}
}
运行结果
0,1,35,66,88,879,