Question: Write a recursive function that reverses a String. A recursive function (as defined in the commentary) is a function that calls itself. The function should

Write a recursive function that reverses a String. A recursive function (as defined in the commentary) is a function that calls itself. The function should return a String and take only one argument, also a String. It should look like this: static String reverse(String s) { ... } (The keyword static simply makes the function easy to call from a main( ) routine in the same class; we learn what it means in the next module.) This function reverse( ) should return the reversed String to the caller, not print the reversed String itself. reverse( ) should follow the rules for well-behaved recursive functions as described in the commentary: in particular, it should use only local variables. The java.lang.String member functions charAt( ) and substring( ) may be useful.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!