← Unit 2 · all exercises
Saved in this browser only

How many digits

Return how many digits a positive number has. 4728 has 4. Dividing by 10 repeatedly gets you there; the number 0 has one digit.

int digits(int n)

Solution.java
Loading editor…
Results

Examples

  • digits(4728) → 4
  • digits(5) → 1

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