forked from jfullstackdev/java-coding-problems
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrimeNumberCheck.java
More file actions
30 lines (24 loc) · 483 Bytes
/
PrimeNumberCheck.java
File metadata and controls
30 lines (24 loc) · 483 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
public class PrimeNumberCheck {
public static void main(String[] args) {
int n;
n = 12;
System.out.print("is ");
System.out.print(n);
System.out.print(" prime number ? ");
System.out.println(isPrime(n));
}
public static boolean isPrime(int n) {
if (n == 0 || n == 1) {
return false;
}
if (n == 2) {
return true;
}
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
}