Loading...
Loading...
Loading...
A phone banking system reads an amount aloud one digit at a time, from left to right. Read n and print the word for each digit, separated by single spaces: 507 becomes five zero seven.
Example 1
Input
507
Output
five zero seven
The middle 0 is read as zero.
Example 2
Input
0
Output
zero
The number 0 has one digit.
Try the problem first. Open one hint at a time.
n % 10 gives digits from the right, but you need them from the left.
Find the place value of the first digit: the largest power of 10 that is at most n (1 for n below 10). For 507 that is 100.
Then the digit is n / place % 10. Divide place by 10 and repeat until place is 0.
An arrow switch turns a digit into its word.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor