Loading...
Loading...
Loading...
A UPI app checks a transaction ID by adding up its digits. Read the ID as a whole number and print the sum of its digits.
int, so read it with nextLong().Example
Input
4096
Output
19
4 + 0 + 9 + 6 = 19.
Try the problem first. Open one hint at a time.
n % 10 gives the last digit and n / 10 removes it.
Repeat while n is greater than 0, adding each last digit to a total.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor