Loading...
Loading...
Loading...
A bank form needs to know how many digits an account balance has. Read an integer n and print how many digits it has. The minus sign of a negative number is not a digit, and 0 has one digit.
Example 1
Input
4502
Output
4
Four digits.
Example 2
Input
0
Output
1
0 is written with one digit.
Try the problem first. Open one hint at a time.
Dividing by 10 with integer division removes the last digit: 4502 / 10 is 450.
Count how many times you can do that before the number becomes 0.
A do-while loop runs at least once, which gives 1 for the input 0.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor