Write a recursive method to reverse a string. Explain why you would not normally use recursion to solve this problem.
What will be an ideal response?
```
public String reverse (String text)
{
String result = text;
if (text.length() > 1)
result = text.charAt(text.length()-1)
+ reverse (text.substring(0, text.length()-1));
return result;
}
```
You would not normally use recursion to solve this problem because it can be done more efficiently using iteration and because the recursive solution is no more intuitive than the iterative solution.
You might also like to view...
An ExecutorService object is created by calling a static method of which class?
a. Executor. b. Executors. c. ExecutorService. d. Thread.
A description of a problem solution at a level a user can understand is a(n) ____________________.
Fill in the blank(s) with the appropriate word(s).
A characteristic of reflection attacks is the lack of _______ traffic.
A. backscatter B. network C. three-way D. botnet
In class LinkedQueue, where does neNodePtr point?
a. the back or end of the chain b. the front or beginning of the chain c. nullPtr d. the next element of the queue