← Unit 2 · all exercises
Saved in this browser only

Is it prime

Return true when the number is prime: greater than 1, and divisible only by 1 and itself.

boolean isPrime(int n)

Solution.java
Loading editor…
Results

Examples

  • isPrime(7) → true
  • isPrime(9) → false

There are also 5 hidden tests you can't see. Solve the problem, not the examples.