-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimeno.java
40 lines (36 loc) · 892 Bytes
/
primeno.java
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
31
32
33
34
35
36
37
38
39
40
package tryproj;
import java.util.*;
public class primeno {
public static void main(String args[])
{
int n;
int status = 1;
int num = 3;
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the value of n:");
n = scanner.nextInt();
if (n >= 1)
{
System.out.println("First "+n+" prime numbers are:");
System.out.println(2);
}
for ( int i = 2 ; i <=n ; )
{
for ( int j = 2 ; j <= Math.sqrt(num) ; j++ )
{
if ( num%j == 0 )
{
status = 0;
break;
}
}
if ( status != 0 )
{
System.out.println(num);
i++;
}
status = 1;
num++;
}
}
}