Demo entry 6761990

庞世伟

   

Submitted by anonymous on Oct 09, 2018 at 10:54
Language: Java. Code size: 742 Bytes.

import java.util.Arrays;  
public class BubbleSort {  
    public static void main(String[] args) {  
        int[] arr = { 6, 3, 8, 2, 9, 1 };  
        System.out.println("排序前数组为:"+Arrays.toString(arr));  
        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;  
                }  
                  
            }  
        }  
        System.out.println("排序后的数组为:"+Arrays.toString(arr));  
        System.out.println();  
        Arrays.sort(arr);  
    }  
}  

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).