-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathprime.java
More file actions
27 lines (27 loc) · 825 Bytes
/
prime.java
File metadata and controls
27 lines (27 loc) · 825 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
import java.util.*;
public class prime{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number you wanna check: ");
int num = sc.nextInt();
int flag = 0;
for(int i=2;i<=num/2;i++){
if(num%i == 0){
flag = 1;
break;
}
else{
flag =0;
}
}
if(flag == 1){
System.out.println("The number "+ num +" is not a prime number");
}
else{
if(num != 1)
System.out.println("The number "+ num +" is a prime number");
else
System.out.println("The number "+num+" is neither prime nor composite");
}
}
}