-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPrime.java
More file actions
executable file
·37 lines (32 loc) · 839 Bytes
/
Prime.java
File metadata and controls
executable file
·37 lines (32 loc) · 839 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
31
32
33
34
35
36
import java.util.*;
public class Prime{
private static Scanner sc;
public static void main(String args[]) {
sc = new Scanner(System.in);
int n =sc.nextInt();
int i=3,j;
boolean flag;
if(n==1)
{
System.out.println("not exist");
System.exit(0);
}
if(n==2||2<n)
{
System.out.println(2);
}
while(i<=n)
{ flag=true;
for (j=2;j<i;j++){
if(i%j==0){
flag=false;
break;
}
}
if(flag){
System.out.println(i);
}
i++;
}
}
}