Need help in Prateek Loves Candy

Please find my code
package challenges_CB_1;

import java.util.Scanner;

public class Ques7 {

public static void main(String[] args) {
	
	Scanner sc = new Scanner(System.in);
	int t = sc.nextInt();
	boolean flag = true;
	int count = 0;
	int j = 0;
	int n1 = 50;
	
	for(int i=0; i<t;i++) {
		
	 int n = sc.nextInt();
	 
	 if (n<=1) {
		 flag = false;
	 }
	 
	 for( j=2 ; j<n;j++) {
		 
		 if(n%j==0) {
			 flag = false;
			 
		 }else {
			 flag = true;
			 count++;
		 }
	 }
	 
	
	 
	 System.out.println(flag);
	
		
	}
}

}

don’t count the prime no
just print the nth prime no

Hi @dekay
i pre calculate the prime numbers but dont know how to compare the index as we’re not using array here, please find code

public class Ques7 {

public static void main(String[] args) {
	
	Scanner sc = new Scanner(System.in);
	int t = sc.nextInt();
	boolean flag = true;
	
	int j = 2;
	int n1 = 2;
	
	int n =0;
	
	for(int i=0; i<t;i++) {
		
	 n = sc.nextInt();
	 
	 for(int i2 =1;i2<10000;i2++) {
		 
		 for( j=2 ; j<i2;j++) {
			 
			 if(i2%j==0) {
				 flag = false;
				 
			 }else {
				 flag = true;	
				 
					
				 }
				 
			 }
		 }
	 }

	 
	
		
	}
}

store the prime no in an arraylist and then just return the required index prime no