java标准高效的冒泡排序

来源:互联网 发布:阿里云 搬瓦工 cn2 编辑:程序博客网 时间:2024/06/06 10:44
public class BSort {    public static void UseSort() {        System.out.println("请输入数字:");        Scanner sc = new Scanner(System.in);        int[] a = new int[5];        for (int i = 0; i < 5; i++) {            a[i] = sc.nextInt();        }        // a int[] a={5,4,3,2,1};        for (int i = 0; i < a.length; i++) {            for (int j = 0; j < a.length - i - 1; j++) {                if (a[j] > a[j + 1]) {                    int temp = a[j];                    a[j] = a[j + 1];                    a[j + 1] = temp;                }            }        }        for (int z : a) {            System.out.printf(z + "----");        }    }    public static void main(String[] args) {        UseSort();    }}
1 0
原创粉丝点击