public class Test4 {
public static void main(String[] args) {
int[] arr = {21, 22, 11, 23, 34, 56, 21, 23, 15, 44};
for (int i = 0; i < arr.length - 1; i++) {
for (int j = 0; j < arr.length - 1 - i; j++) {
if (arr[j] > arr[j + 1]) { //从小到大排序
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
for (int b : arr) {
System.out.print(b + " ");
}
}
}
java冒泡排序
于 2022-02-24 13:06:58 首次发布