Prateek loves candy

arraylist does not declare

        Scanner scn = new Scanner(System.in);

        int n = scn.nextInt();

        int[] cases = new int[n];
        int max = 0;

        for (int i = 0; i < cases.length; i++) {

            cases[i] = scn.nextInt();
            max = Math.max(max, cases[i]);
        }

        ArrayList primes = getPrimes(max);

        for (int i = 0; i < cases.length; i++) {

            System.out.println(primes.get(cases[i] - 1));
        }
    }

    public static ArrayList getPrimes(int n) {

        boolean[] board = new boolean[1_000_001];

        board[0] = true;
        board[1] = true;

        for (int table = 2; table * table <= 1000000; table++) {

            if (!board[table])
                for (int mult = 2; table * mult <= 1000000; mult++) {
                    board[table * mult] = true;
                }
        }

        ArrayList ans = new ArrayList<>();

        int cnt = 0;
        for (int i = 2; cnt <= n; i++) {

            if (!board[i]){
                ans.add(i);
                cnt++;
            }
        }

        return ans;
    }

You cannot declare an ArrayList without a type. If you wanna store just Integers in it, use ArrayList A= new ArrayList<>();

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.