编辑代码

public class BubbleSort {
    public static void main(String[] args) {
        int[] arr1 = {11, 9, 3, 20, 56, 32};
        int[] arr2 = {5, 2, 9, 1, 5, 6};
        int[] arr3 = {10, 8, 6, 4, 2, 0};
        
        System.out.println("Test Case 1 (Bubble Sort):");
        bubbleSort(arr1);
        printArray(arr1);
        
        System.out.println("Test Case 2 (Bubble Sort):");
        bubbleSort(arr2);
        printArray(arr2);
        
        System.out.println("Test Case 3 (Bubble Sort):");
        bubbleSort(arr3);
        printArray(arr3);
    }
    
    public static void bubbleSort(int[] arr) {
        int n = arr.length;
        for (int i = 0; i < n - 1; i++) {
            for (int j = 0; j < n - i - 1; j++) {
                if (arr[j] > arr[j + 1]) {
                    // Swap arr[j] and arr[j + 1]
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
    }
    
    public static void printArray(int[] arr) {
        for (int num : arr) {
            System.out.print(num + " ");
        }
        System.out.println();
    }
}