Challenge 2: Check for Prime Number

In this lesson, you will implement the code to check if a number is prime using recursion.

What is a prime number?

A prime number is a number greater than 1 that has only two divisors: 1 and the number itself. The first few prime numbers are:

2,3,5,7,11,13,17,19,23,29,.....2, 3, 5, 7, 11, 13, 17, 19, 23, 29, .....

Composite numbers are numbers that are not prime; that is, they have divisors other than 11 and itself

4,6,8,9,10,12,14,15,16,18.......4, 6, 8, 9, 10, 12, 14, 15, 16, 18.......

The numbers 11 and 00 are neither prime nor composite.

All the numbers are either prime or composite, except for 00 and 11.

Problem Statement

Write a recursive method, named isPrime() that checks if a number is prime or not.


  1. The method should take two integers as input.
  2. The method should return Boolean, meaning it will return true if the number is prime or return false if the number is not prime.
  3. The method should be recursive.

Sample Input: 7

Sample Output: true

Sample Input: 9

Sample Output: false

Good luck!

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.