We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5d77b08 commit 2f62929Copy full SHA for 2f62929
1 file changed
βMaths/PrimeCheck.javaβ
@@ -21,6 +21,12 @@ public static void main(String[] args) {
21
* @return {@code true} if {@code n} is prime
22
*/
23
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
30
for (int i = 3; i <= Math.sqrt(n); i += 2) {
31
if (n % i == 0) {
32
return false;
0 commit comments