Code:
import java.util.Scanner;class prime {
public static void main(String[] args) {
int n,num=3,status=1;
Scanner in=new Scanner(System.in);
System.out.print("Enter the limit : ");
n=in.nextInt();
if (n>1) {
System.out.println(2);
}
for (int count = 2; count <= n;)
{
for (int j = 2; j <= Math.sqrt(num) ; j++)
{
if (num%j==0)
{
status=0;
break;
}
}
if (status!=0)
{
System.out.println(num);
count++;
}
status=1;
num++;
}
}
}
No comments:
Post a Comment