forked from deepanshdubey/JavaAssignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstNPrime.java
More file actions
30 lines (28 loc) · 737 Bytes
/
FirstNPrime.java
File metadata and controls
30 lines (28 loc) · 737 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//Author : Deepansh Dubey.
//Date : 2/09/2021.
//Purpose : To print first n prime numbers.
import java.io.*;
class FirstNPrime{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int p,i,j,counter=0,k=0;
System.out.println("Please enter the no.");
p=Integer.parseInt(br.readLine());
for(i=2;counter<=p;i++)
{
for(j=1;j<=i;j++)
{
if(i%j==0)
{
k++;
}
}
if (k==2)
{
System.out.print("\t"+i);
}
k=0;counter++;
}
}
}