Question: i dont understand this, how u get return (n % 10) + sumDigits(n/10); and if (n Given a non-negative int n, return the sum of

i dont understand this, how u get return (n % 10) + sumDigits(n/10); and if (n Given a non-negative int n, return the sum of its digits recursively (no loops). Note that mod (%) by 10 yields the rightmost digit (126 % 10 is 6), while divide (/) by 10 removes the rightmost digit (126 / 10 is 12). sumDigits(126) 9 sumDigits (49) 13 sumDigits(12) 3 Run 9 Expected sum Digits(126) 9 sumDigits(49) Go OK ...Save, Compile, Run (ctrl-enter) + 13 13 OK sum Digits(12) 3 3 OK public int sumDigits(int n) { if (n Recursion-1
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
