Skip to main content

Practice · 1 of 5

Recursive digit count

CHALLENGE
Difficulty: intermediate+25 XP

Implement int numDigits(int n) recursively (n >= 0): 0 has 1 digit; otherwise 1 + numDigits(n / 10). The base case is n < 10, not n == 0 — think about why both work here.

Back to lesson: Practice: Recursion lab