Question: Part #1 Write a recursive method that takes a word as input and displays that word with all characters separated by a space. It should
Part #1
Write a recursive method that takes a word as input and displays that word with all characters separated by a space. It should have this signature:
Public static void addSpaces(String strWord)
For example, addSpaces(hello) displays h e l l o. Use the main() method to ask the user to enter a word and then call addSpaces().
Part #2
Write a recursive method that calculates the sum of integers in an array. The signature should be:
Public static int sumArray(int[] iArray)
For example, sumArray({1,2,3,4}) returns 10. Make up a small array and then pass it into the method from main() to test it.
Hint: You could use System.arraycopy() to copy the array to a new smaller array each time.
Note
Take note of the return types. Part 1 returns void so theres no return statement. Start building the output in the addSpaces() method (before the recursive call). Part 2 returns int so the return statement will look something like the Factorial example.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
