Saturday, 31 August 2013

I'm trying to find the sum of primes below million

I'm trying to find the sum of primes below million

I'm trying to find the sum of primes below millions..my code works when I
try to find the sum of primes below hundred thousands but when I go large
numbers it doesn't work....so I need some help to get this work for big
numbers...
import java.util.Scanner;
public class sumPrime {
public static void main (String args []){
long n = 2000000; int i; int j;int sum =0;
for (i=2; i <n; i++){
for (j=2; j<i; j++){
if (i%j==0){
break;
}
}
if (i==j){
sum +=i;
}
}
System.out.print(sum);
}
}

No comments:

Post a Comment