Runtime Error Problem

import java.util.*;
public class Main {
// mark all prime no
static void primeSieve(boolean prime[]) {
for (int i = 3; i < prime.length; i = i + 2) {
prime[i] = true;
}

	for (int i = 3; i <= prime.length; i = i + 2) {
		// if the current no is marked
		if (prime[i] == true) {
			// marked all current no multiple as not prime
			for (int j = i * i; j < prime.length; j = j + i) {
				prime[j] = false;
			}
		}
	}

	prime[2] = true;
	prime[0] = prime[1] = false;
}
// using sieve erathosthenes approach
public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

	boolean[] prime = new boolean[1000000];
	primeSieve(prime);

	int T = sc.nextInt();
	
	int count = 0;
	int num = 0;

	while(T!=0) {
		int no = sc.nextInt();
		for (int i = 2; i <= prime.length; i++) {
			if (count == no) {
				break;
			} else {
				if (prime[i] == true) {
					num = i;
					count++;
				}
			}

		}
		no=0;
		count=0;
		System.out.println(num);
	}
}

}

@nigamshubham1998,

   for (int i = 3; i <= prime.length; i = i + 2) {

Here i*i<prime.length

Also to avoid TLE, store all prime numbers in an arraylist and when you have to print the number just call the integer at that particular index.

I do the changes still runtime error is coming pls help

i do the changes still runtime error is coming import java.util.; public class Main { // mark all prime no static void primeSieve(boolean prime[]) { for (int i = 3; i < prime.length; i = i + 2) { prime[i] = true; } for (int i = 3; ii < prime.length; i = i + 2) { // if the current no is marked if (prime[i] == true) { // marked all current no multiple as not prime for (int j = i * i ; j < prime.length; j = j + i) { prime[j] = false; } } } prime[2] = true; prime[0] = prime[1] = false; } // using sieve erathosthenes approach public static void main(String args[]) { Scanner sc = new Scanner(System.in); boolean[] prime = new boolean[10000]; primeSieve(prime); int T = sc.nextInt(); int count = 0; int num = 0; while(T!=0) { int no = sc.nextInt(); for (int i = 2; i <= prime.length; i++) { if (count == no) { break; } else { if (prime[i] == true) { num = i; count++; } } } no=0; count=0; System.out.println(num); } } }

@nigamshubham1998,
https://ide.codingblocks.com/s/253474 corrected code.

Use an arraylist. Size of prime will be 1000001.