Something is wrong with my code that i can’t figure it out, will you help me to find my mistake? Thank you!
/// Calculate Prime
private static int countPrimes(int number){
int count =0;
for(int i=1; i<=MAX_PRIME; i++) {
if(isPrime(i)){
count++;
}
}
System.out.println("Exactly "+ count + " prime numbers exist between "+number + " and 1000.");
return number;
}
here is my result:
Exactly 180 prime numbers exist between 1 and 1000. Which is wrong and has to be 168!!!
What the function isPrice()? is it a function to check that a integer number is prime number or not? I think that if you have it, you just need to do like this: