I am trying to find the sum of all the primes below 2000000, and my program works fine until I enter any number larger than 225287, after which it starts giving incorrect answers. Any ideas?
public class PrimeSum {
public static void main(String[] args) {
PrimeSum is = new PrimeSum();
int total = 0;
for(int i = 2; i < 225287; i ++){
if(is.isPrime(i)){
total += i;
System.out.println(i);
}
}
System.out.println(total);
}
boolean isPrime(int i ){
Boolean prime = true;
for(int n = 2; n< i; n++){
if(i % n == 0){
prime = false;
break;
}
}
return prime;
}
}