Week 2 :
a)
Write a Java program that prompts the user for an integer
and then prints out all prime numbers up to that integer.
import java.lang.*;
import java.io.*;
class prime
{
public static void main(String args[])
{
int n=Integer.parseInt(args[0]);
for(int r=0;r
{
int t=0;
for(int i=1;i
{
if (r%i==0)
{
t++;
}
}
if(t<2)
{
system.out.print(r);
system.out.print(" ");
}
}
}
}
No comments:
Post a Comment