# Sum Of The First 1000 Prime Numbers | Java Program

Do you know what is the sum of first 1000 prime numbers?
see how to find it easily using Java Programming, Here's the code :

```public class Main {
public static int isPrime(int i){
int flag=0;
for(int j=2;j<i;j++)
{
if(i%j==0)
{
flag=1;
break;
}
}
return flag;
}
public static void main (String[] args){
System.out.println("******* SUM OF PRIMES *******");
int sum=-1;
for (int i=1,c=0;c<=1000;i++){
if(isPrime(i)==0){
sum=sum+i;
c++;
}
}
System.out.println("RESULT :  "+sum);
}
}
```

OUTPUT :

can you please give me the code for this question???????????
Q:Check whether the given number is a prime number or not if it is not then print nearest prime number??????

Nice program.... Check the below Code:
import java.io.*;

public class series {
public static void main ( String arg[] ) throws IOException{
System.out.print("Enter Number: ");
if(isPrime(num)){
System.out.println(num + " is prime.");
} else{
System.out.print(num + " is not prime " + prePrime(num) + " is prime");
}
}
public static Boolean isPrime(int n){   //check for prome or not
for(int i=2;i<n;i++){
if(n%i==0)
return false;
}
return true;
}
public static int prePrime(int n){      //Find previous prime
int i , check;
for(i=n-1;i>2;i--){
check = 0;
for(int j=2;j<i;j++){
if(i%j==0){
check =1;
break;
}
}
if(check==0)
break;
}
return i;
}
}