Question: Write a recursive method digitSum that takes a non-negative integer in return for some of its digits. For example, digitSum(1234) returns 1 + 2 +

 Write a recursive method digitSum that takes a non-negative integer in

Write a recursive method digitSum that takes a non-negative integer in return for some of its digits. For example, digitSum(1234) returns 1 + 2 + 3 + 4 = 10. Your method should take advantage of the fact that it is easy to break a number into two smaller pieces by dividing by 10 (i.e, 1234/10 = 123 and 1234%10 = 4). For these methods, we do not need to construct any objects. Therefore, you can declare them to be static methods and call them directly from main: public static int digitSum(int n) {ellipsis}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!