【java算法】 两个数组合并成一个数组,并进行排序,打印出来

public static void main(String[] args) {
        int[] a = {3,1,9,5,0};
        int[] b = {8,2,4,7,6};
        int[] c = new int[a.length + b.length];
        System.arraycopy(a,0,c,0,a.length);
        System.arraycopy(b,0,c,a.length,a.length);
//        Arrays.sort(c);
        c = bubbleSort(c);
        System.out.println(Arrays.toString(c));
    }

    public static int[] bubbleSort(int[] a) {

        int len = a.length;
        // 外层控制比较轮次
        for (int i = 0; i < len; i++) {
            // 内层控制比较次数
            for (int j = 0; j < len - i - 1; j++) {

                if (a[j] > a[j+1]){

                    int tmp = a[j];

                    a[j] = a[j+1];

                    a[j+1] =tmp;

                }
            }
        }

        return a;
    }

 

你可能感兴趣的:(java,算法)