这里主要就是考察对异或的灵活使用(^)

- 根据异或(^)的性质(可以消除重复的数字)求解、

    @Test
    public void test5() {
   
        int N = 1001;//数组的长度【0-1000】
        int[] array = new int[N];
        //向数组中依次存值(最后留出一个位置)
        for (int i = 0; i < array.length - 1; i++) {
   
            array[i] = i + 1;
        }
        //最后一个位置的随机数【1-1000】存入数组中
        Random random = new Random();
        int ran = random.nextInt(N - 2) + 1;
        array[N - 1] = ran;
// 打印数组
        System.out.println(Arrays.toString(array));
        int result = 0;
        for (int i = 1; i < N; i++) {
   
            result = result ^ i;
        }
        //result=0^1^2^3^4^5^6^7^8^9^10
        //然这个式子与数组中的每一个数求异或,根据异或的性质,多出来的那个就是结果,
        for (int i = 0; i < N; i++) {
   
            result = result ^ array[i];
        }
        System.out.println("结果" + result);

    }

- 若是没有题目中的要求可以用暴力法直接求解

 public void test6() {
   
        int N = 1001;//数组的长度【0-1000】
        int[] array = new int[N];
        //向数组中依次存值(最后留出一个位置)
        for (int i = 0; i < array.length - 1; i++) {
   
            array[i] = i + 1;
        }
        //最后一个位置的随机数【1-1000】存入数组中
        Random random = new Random();
        int ran = random.nextInt(N - 2) + 1;
        array[N - 1] = ran;
// 打印数组
        System.out.println(Arrays.toString(array));

        int[] a=new int[N];
        for (int i = 0; i <N ; i++) {
   
            a[array[i]]++;
        }
        for (int i = 0; i <N ; i++) {
   
            if (a[i]==2){
   
                System.out.println(i);
                break;
            }
        }

    }