Prateek loves Candy

why does my code not work
it keeps on expecting inputs when i tried it on eclipse ide.
Code:
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner input = new Scanner(System.in);
int T = input.nextInt();
int n,num,counter;
boolean val;
for(int t=1 ; t<=T;t++){
val=true;
n = input.nextInt();
num=2;
counter=0;
while(counter!=n){
for(int divisor=2;divisor<num;divisor++){
if(num%divisor==0){
val=false;
}
}
if(val==true){
counter++;
}
if(counter==n){
break;
}
num++;
}
System.out.println(num);
}
input.close();
}
}

check your code. Your inside while is running infinitely for n>2
Also, a better approach would be to use sieve of erastothenes

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.