1.WAJP
that prompts the user for an integer and then prints out all the prime numbers
up to that Integer.
Program:
class Prime
{
public static void main(String args[])
{
System.out.println(1+",");
int n=Integer.parseInt(args[0]);
boolean flag=false;
for(int i=2;i<=n;i++)
{
int fact=2;
while(fact<=i/2)
{
if(i%fact==0)
{
flag=true;
break;
}
fact++;
}
if(flag==false)
System.out.println(i);
}
}
}
0 comments:
Post a Comment