public static void main(String[] args) {
int[] array = {2, 3, 5, 1, 0, 7};
int num;
for (int i = 0; i < array.length; i++) {
for (int j = 0; j < array.length - i - 1; j++) {
if (array[j] > array[j + 1]) {
num = array[j];
array[j] = array[j + 1];
array[j + 1] = num;
}
}
}
for (int c : array) {
System.out.println(c);
}
}
java冒泡排序
于 2022-01-20 12:05:22 首次发布