-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEach_loop3.java
More file actions
30 lines (27 loc) · 815 Bytes
/
Copy pathEach_loop3.java
File metadata and controls
30 lines (27 loc) · 815 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
package loop;
import java.util.Scanner;
public class Each_loop3 {
public static void main(String[] args) {
int temp;
boolean isPrime = true;
int num;
try (Scanner scan = new Scanner(System.in)) {
System.out.print("Enter any number :"); // capture the input in an integer
num = scan.nextInt();
} // capture the input in an integer
for(int i=2;i<=num/2;i++){
temp=num%i;
if(temp==0){
isPrime=false;
break;
}
}
// If isPrime is true then the number is prime else not
if(isPrime){
System.out.println(num+" is a Prime Number");
}
else{
System.out.println(num+"is not a Prime Number");
}
}
}