programming-examples/java/_Basics/Program to find the sum of the first 1000 prime numbers (Java).java

35 lines
788 B
Java
Raw Normal View History

2019-11-15 12:59:38 +01:00
/*
Program to find the sum of the first 1000 prime numbers.
*/
public class Main
{
public static void main(String args[])
{
int number = 2;
int count = 0;
long sum = 0;
while(count < 1000)
{
if(isPrimeNumber(number))
{
sum += number;
count++;
}
number++;
}
System.out.println(sum);
}
private static boolean isPrimeNumber(int number)
{
for(int i=2; i<=number/2; i++)
{
if(number % i == 0)
{
return false;
}
}
return true;
}
}