打印出指定数组,随机生成不重复的数

private static void getUnDeNumber(int[] arr) {
        int n = arr.length;
        for (int j = n; j > 1; j--) {
            int random = (int) (Math.random() * j);
            System.out.printf("get a number:" + arr[random] + "\n");
            System.arraycopy(arr, random + 1, arr, random, n - 1 - random);
            arr = Arrays.copyOf(arr, n - 1);
            n--;
        }
    }

你可能感兴趣的:(打印出指定数组,随机生成不重复的数)