The code is as follows:

Public static void Main (String[] args) {int[] arr = {3, 5, 6, 2, 1}; public static void Main (String[] args) {int[] arr = {3, 5, 6, 2, 1}; arrPrint(arr); BubbleSort(arr); arrPrint(arr); } // The first level of the for loop, I from the end of the arR to the end. // The second level of the for loop, j is traversed from the beginning to I. // After the loop of j completes once, I shifts to the left, and the traversal range of J is shortened by one bit. private static void BubbleSort(int[] arr) { int temp = 0; for (int i = arr.length - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (arr[j] > arr[j + 1]) { temp = arr[j + 1]; arr[j + 1] = arr[j]; arr[j] = temp; Private static void arrPrint(int[] arr) {StringBuilder STR = new StringBuilder(); str.append("["); for (int v : arr) { str.append(v + ", "); } str.delete(str.length() - 2, str.length()); str.append("]"); System.out.println(str.toString()); }}Copy the code

After omitting