Write a recursive method that will compute the sum of the digits in a positive number.
What will be an ideal response?
```
public static long sumDigits(long number){
long result;
if(number == 0)
// base case
result = 0;
else {
long digit = number % 10;
if(digit < 0)
digit = -1 * digit;
result = digit + sumDigits(number/10);
}
return result;
}
```
This code is in Methods.java.
You might also like to view...
To check if a string s contains the prefix "Java", you may write
a. if (s.startsWith("Java")) ... b. if (s.indexOf("Java") == 0) ... c. if (s.substring(0, 4).equals("Java")) ... d. if (s.charAt(0) == 'J' && s.charAt(1) == 'a' && s.charAt(2) == 'v' && s.charAt(3) == 'a') ...
You can specify scaling to reduce or enlarge a worksheet for printing.
Answer the following statement true (T) or false (F)