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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started