forked from anisul-Islam/java-documentation-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrime.java
More file actions
29 lines (26 loc) · 645 Bytes
/
Copy pathPrime.java
File metadata and controls
29 lines (26 loc) · 645 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
import java.util.Scanner;
// 2 3 5 7 11 13 17 19 23 ....
class Prime{
public static void main(String[] args) {
try (Scanner input = new Scanner(System.in)) {
System.out.print("Enter any positive integer: ");
int num = input.nextInt();
int count = 0;
if(num == 0 || num==1){
System.out.println("Not Prime");
}else{
for(int i=2; i<num/2; i++){
if(num%i==0){
count++;
break;
}
}
if(count==0){
System.out.println("Prime number");
}else{
System.out.println("Not Prime");
}
}
}
}
}