✕
Functions and ScopeCoding problems
Functions and Scope: coding problems
Write a program that reads the input and prints the answer. Run checks it against every test, including hidden ones.
0 of 7 solved
A shop prints a check code on every receipt. The code is the sum of the digits of the amount, ignoring the sign, so
-4096gives 19.Write a recursive method
sumDigits(long n)that adds the last digit to the sum of the rest, with a base case for a single digit. Read one number and print its digit sum.Input. One line with a whole number n, where -10^18 <= n <= 10^18.
Output. One integer: the sum of the digits of the absolute value of n.
Example 1 input
0
Output
0
Example 2 input
9
Output
9