Question: work as .java Write a method using the prototype below, that returns the sum of the digits of the integer specified as an argument. Obviously,
work as .java
Write a method using the prototype below, that returns the sum of the digits of the integer specified as an argument. Obviously, this method should use recursion.
int sumOfDigits(int x);
If x is 234, the function should return 2 + 3 + 4, that is, 9.
If x is 12, the function should return 1 + 2, which is 3.
If x is 39, the function should return 12.
If x is negative, ignore the minus sign. For example, -12 and 12 both return 3.
Use recursion.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
