冒泡排序

public class Demo {
public static void main(String[] args) {

//冒泡排序
int[] ints = {3,2,43,54,32,22,-2,34,66,35};
int temp;
for (int i = 0; i < ints.length - 1; i++) {//从第i个数开始

for (int j = 0; j < ints.length - 1; j++) {//比较j次 如果比后面数大就交换
if(ints[j] > ints[j + 1]){
temp = ints[j];
ints[j] = ints[j + 1];
ints[j + 1] = temp;
}
}
}
for (int i = 0; i < ints.length; i++) {
System.out.println(ints[i]);
}

}
}
posted @ 2022-07-11 20:47  在努力啊啊啊啊  阅读(19)  评论(0编辑  收藏  举报