Question: Write recursive Java methods to do the following tasks. There are other ways to accomplish these tasks, but this is an exercise in writing recursive
Write recursive Java methods to do the following tasks. There are other ways to accomplish these tasks, but this is an exercise in writing recursive code. You do not need to take user input; write either a driver class or JUnit tests to create the input Strings and run the functions.
1. Count the characters in a string by stripping the first character recursively and returning a count, which increases as the recursion unwinds. Make sure this works with a string of length 0. Return the int length.
2. Reverse the characters in a string. Do this by stripping off the first character in each recursive call, then adding them them to end of the string as the recursion unwinds. Return the reversed string.
3. Determine whether a string is a palindrome (like 'Madam, I'm Adam'). Strip the first and last characters in each instance of the function and compare them for equality. Make sure the termination condition for the recursion works correctly for strings of both odd and even lengths. Convert all letters to lower case with toLowerCase() and use the static method Character.isLetter() to create a String containing only letters. You will also need the String method charAt(), which gets a char from the String by index. Return a boolean. This function will run slowly, so use short phrases (no more than about 20 characters) to test it.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
