Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

13-1 How does building new systems produce organizational change?

Answered: 1 week ago