Java Write Test Recursive Function Determines String Matching Character Distance Either En Q37221927

In java, Write and test a RECURSIVEfunction that determines if a string has a matchingcharacter the same distance from either end. No loops areallowed.                        

                                                       

Examples of strings that should return true:

  

“Starts”                       second character t      matchessecond-last character t      

“false”                        third character    l       matches third-last character       l         

“What About Bob?”    5th characterspace     matches 5th-last character        space

   Examples of strings that should return false:

“no”                                  

“true”                               

“recursion and iteration!”


Answer


Here is code:

class PalindromeCheck {

public static boolean isPalindrome(String s) {

s = s.toLowerCase();

if (s.length() == 0 || s.length() == 1)// if length is 0 or 1then String is palindrome

return true;

if (s.charAt(0) == s.charAt(s.length() – 1))

return isPalindrome(s.substring(1, s.length() –

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.