Question: The following method has a bug that leads to infinite recursion. What correction fixes the code? // Adds the digits of the given number. //
The following method has a bug that leads to infinite recursion. What correction fixes the code?

// Adds the digits of the given number. // Example: digitsum (3456) returns 3+4+5+6 = 18 public static int digitSum (int n) { if (n > 10) { // base case (small number) return n; } else { // recursive case (large number) return n % 10 + digitsum (n / 10);
Step by Step Solution
3.48 Rating (164 Votes )
There are 3 Steps involved in it
The base case if statement ... View full answer
Get step-by-step solutions from verified subject matter experts
