Skip to content

Commit

Permalink
Merge pull request TheAlgorithms#939 from 0Zeta/0zeta/prime-check-cor…
Browse files Browse the repository at this point in the history
…rection

Correct prime check
  • Loading branch information
yanglbme authored Oct 2, 2019
2 parents 5d77b08 + 2f62929 commit b8b2938
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Maths/PrimeCheck.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public static void main(String[] args) {
* @return {@code true} if {@code n} is prime
*/
public static boolean isPrime(int n) {
if (n == 2) {
return true;
}
if (n < 2 || n % 2 == 0) {
return false;
}
for (int i = 3; i <= Math.sqrt(n); i += 2) {
if (n % i == 0) {
return false;
Expand Down

0 comments on commit b8b2938

Please sign in to comment.