Java Program to Find Prime Numbers

Here is a simple Java program to find prime no. The values of n is already given.import java.io.*;
class prime
{
public static void main(String args[]) throws IOException
{
System.out.println(“The prime numbers are”);
System.out.println(” “);
int c,i;
for(i=0;i<=1000;i++)
{
c=2;
while(c<=i-1)
{
if(i%c==0)
break;
c++;
}
if(c==i)
{
System.out.print(i + ”  “);
}
}
}
}

Add Comment