给你从小到大排序的例子 public void bubbleSort() { System.out.println("冒泡排序:"); int[] array1 = { 9, 8, 7, 6, 5, 4, 3,2,1 }; int i = 0; int j = 0; for (i = 0; i < array1.length - 1; i++) { for (j = 0; j < array1.length - i - 1; j++) { if (array1[j] > array1[j + 1]) { int index = array1[j + 1]; array1[j + 1] = array1[j]; array1[j] = index; } } }