public static void main(String[] args) { int[] arry = {9, 8, 7, 6, 5, 4, 3, 2, 1}; for (int i = 0; i < arry.length; i++) { for (int j = 0; j < arry.length - 1 - i; j++) { if (arry[j] > arry[j + 1]) { int temp = arry[j]; arry[j] = arry[j + 1]; arry[j + 1] = temp; } } } for (int a : arry) { System.out.print(a + " "); } }
最外面是一共循环了多少趟
里面的循环是一趟中比较了多少次