Why MY CODE GIVE TLE

import java.util.*;
public class Main {
public static void main(String args[]) {

	Scanner sc = new Scanner(System.in);
	int t=sc.nextInt();
	while(t-- > 0){
		int num=sc.nextInt();
		System.out.println(primeNo(num));
	}
}
static int primeNo(int n){
	int num=0;
	for(int i=2 ; i<1000000;i++){boolean cond = true;
	 int num1=2;
      while(num1 <=i/2  ){
		  if(i%num1 == 0){
			  cond =false;
			  break;
		  }num1++;
	  }
	  if(cond) num++;
	  if(n==num)  return i;
	}
    return 0;
}

}

@akshatj07 Hi buddy reviewing it!

@akshatj07 bro so here’s my suggestion to you. While doing these kinds of questions try to minimize the redundant operations.

Here it is calculating primes.
Think if T is like 10^4 and n is 10^6 and in worst case each of the test cases has very large value so you will be computing primes again and again and that will give you a TLE.

So precompute the primes once upto the given constraints, you will be good to go.

Remember my advice. If your query is resolved then resolve the doubt and rate full else feel free to ask doubt bro!