Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started