Question: Your code must use recursion to accomplish the following task. You will not receive credit for a solution (even if it passes the Mimir tests)
Your code must use recursion to accomplish the following task. You will not receive credit for a solution (even if it passes the Mimir tests) that uses loops or doesn't actually use recursion.
Complete the RECURSIVE method sumOfDigits() that computes the sum of the digits of the given positive integer argument, n
e.g., if n = 5403, the method will return: 5+4+0+3 = 12 note: the right-most (1's) digit can be found using n%10 (5403 % 10 is 3, for example) the remaining digits (all but the 1's digit) can be found using n/10 (5403 / 10 is 540, for example)

1 - 2 3 4 public class Digits { public static int sumofDigits(int n) { //TODO: complete this method } 5 6 public static void main(String[] args) { 7 //this main method is not used by Mimir's tests 8 //you can write your own if you want to test the f() method directly 9 //by running it in your IDE 10 } 11 }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
