Skip to main content

Practice · 2 of 5

Primality test

CHALLENGE
Difficulty: beginner+25 XP

Implement boolean isPrime(int n): true when n >= 2 and no divisor between 2 and sqrt(n) divides it. Loop with i * i <= n to avoid floating point.

Back to lesson: Practice: Method toolkit