Modify the previous exercises Recurse program so that it uses tail recursion. Minimize code changes. You should
Question:
Modify the previous exercise’s Recurse program so that it uses tail recursion. Minimize code changes. You should be able to do this with exactly the same number and sequence of statements and with only internal alterations to one line in the main method and three lines in the recurse method.
Exercise 11.3
Many times, you have used Scanner methods to read and parse keyboard input. You can also use those same Scanner methods to read and parse an ordinary string. The following program uses the Scanner class’s now-familiar next method, but this time it reads from a string instead of the keyboard. When the next method executes, there’s an internal cursor that remembers how much of the string has been processed so far and how much has yet to be processed. The program uses the Scanner class’s hasNext method to check whether there is any more of the string that has yet to be processed. Study the code. What does the program display for output? Note the recursive return statement that says “// explain.” Explain how that statement works.
Step by Step Answer:
Introduction To Programming With Java A Problem Solving Approach
ISBN: 9781260575248
3rd International Edition
Authors: John Dean