Expected time required: 10 min
Now that we've gone through the steps to determine our base case and recursion cases, let's go ahead and write the recursive method that counts down from a target number and returns a String combining the digits together into a single String.
-
Example Input: 3
-
Example Final Return: "3210"
In the previous two questions, we established that our base case was when our target number gets to zero. Anything else and we will continue to make a recursive call to our method as we count down.
In this activity, you will need to:
- Modify the
countDown
method of theRecursiveCountDown
class in order to turn it into a true recursive method that creates the desired result. - Do some testing via the
main
method inRecursionPractice
that starts the recursive method. You may want to modify that main method to test other values in your recursive method. - After verifying that
RecursionPractice
gives the expected results, make sure that theRecursiveCountDownTest
file is passing, then commit and push your changes.
HINT: