The following method has a bug that leads to infinite recursion. What correction fixes the code? //

Question:

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

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question

Building Java Programs A Back To Basics Approach

ISBN: 9780135471944

5th Edition

Authors: Stuart Reges, Marty Stepp

Question Posted: