logo CodeStepByStep logo

canMakePalindrome

Language/Type: Java string parameters return boolean
Related Links:

Write a method named canMakePalindrome that accepts a string parameter and returns true if you can make that string into a palindrome by deleting at most 1 character, or false if that is not possible.

For this problem, a palindrome is defined as a string that contains exactly the same sequence of characters forwards as backwards. For example, "madam" and "abba" and "racecar" are palindromes. The empty string and all one-character strings are also palindromes by our definition.

If a string that is already a palindrome is passed, you should return true, such as the call of canMakePalindrome("racecar"). You should also return true if the string would be a palindrome after the removal of a single character, such as "raycecar" (remove the 'y') or "abxa" (remove the 'x').

Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.