Skip to content

Commit b8b2938

Browse files
authored
Merge pull request TheAlgorithms#939 from 0Zeta/0zeta/prime-check-correction
Correct prime check
2 parents 5d77b08 + 2f62929 commit b8b2938

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Maths/PrimeCheck.java

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ public static void main(String[] args) {
2121
* @return {@code true} if {@code n} is prime
2222
*/
2323
public static boolean isPrime(int n) {
24+
if (n == 2) {
25+
return true;
26+
}
27+
if (n < 2 || n % 2 == 0) {
28+
return false;
29+
}
2430
for (int i = 3; i <= Math.sqrt(n); i += 2) {
2531
if (n % i == 0) {
2632
return false;

0 commit comments

Comments
 (0)