package com.alok;
import java.io.*;
class Prime_check
{
public static void main(String[] args) throws Exception
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter Limit:");
int num = Integer.parseInt(br.readLine());
System.out.println("Prime numbers: ");
for (int i=1; i < num; i++ )
{
int j;
for (j=2; j<i; j++)
{
int n = i%j;
if (n==0)
{
break;
}
}
if(i == j)
{
System.out.print(" "+i);
}
}
}
}
O/P:-
Enter Limit:
50
Prime numbers:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
No comments:
Post a Comment