I have to find the 10001st prime number which is 104753 but when I run my code I get 104754.
I need help finding the problem. What can I change so it finds the 10001st prime number ? Thanks
This is what I've done so far :
public class Prime
{
public static void main(String[] args)
{
int a = 1;
int primes = 0;
while (primes < 10001)
{
if (isPrime(a) == true)
{
primes++;
}
a++;
}
System.out.println("The 10001st prime number is " + a);
}
public static boolean isPrime(int b)
{
boolean x = false;
int counter = 0;
for (int i=1; i<=b; i++)
{
if (b%i == 0)
{
counter++;
}
if (counter == 2 && i == b)
{
x = true;
}
}
return x;
}
}