Question: Problem 1. Implement a recursive method printDigits() that takes an integer num as a parameter and prints its digits, one digit per line. For example,

Problem 1.

Implement a recursive method printDigits() that takes an integer num as a parameter and prints its digits, one digit per line. For example, the output for the method call printDigits(23145) would display 2 3 1 4 5

Problem 2.

Implement a recursive method sumArray() that returns the sum of the first numbersToAdd numbers in the array. The method takes two parameters: 1. a non-empty integer array, numArray 2. numbersToAdd, a positive integer representing the number of entries in array to add, no more than size of the array.

You may assume valid parameters. For example, int[] a ={1,3,2,5}; System.out.println(sumArray(a,3)); //will display 6 System.out.println(sumArray(a,4)); //will display 11

Problem 3. Test all methods above in a program, TestRecursion, by using examples and/or instructions given in each problem.

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!