public class Maopaopaixu {
public static void main(String[] args) {
// 冒泡排序
int[] x = { 3, 7, 9, 1, 5 };
int temp;
for (int i = 0; i < x.length - 1; i++) {
for (int j = 0; j < x.length - i - 1; j++) {
if (x[j] > x[j + 1]) {
temp = x[j];
x[j] = x[j + 1];
x[j + 1] = temp;
}
}
}
// foreach循环
for (int a : x) {
System.out.print(a + " ");
}
}
}
1 3 5 7 9 冒泡排序
最新推荐文章于 2022-08-27 20:55:53 发布