Pages

Tuesday, July 3, 2012

find Prime numbers program in java

Write a program that prints prime numbers between 1 to n. Number n should be acepted as command line input.



class PrimeNumber {

public static void main (String args[])

{

int num=Integer.parseInt(args[0]);

int i,j;

for(i=1;i
{

for(j=2;j
{

int n=i%j;

if(n==0) {break;}

}

if(i==j)

{

System.out.print(" " + i);

}

}



}

}

No comments:

Post a Comment