Solution Review: Is this String a Palindrome?
This lesson provides a detailed review of the solution to the challenge in the previous lesson.
Solution: Palindrome or not?
Press + to interact
class ChallengeClass {public static boolean isPalindrome(String text) {if (text.length() <= 1) {return true;}else {if (text.charAt(0) == text.charAt(text.length()-1)) {return isPalindrome(text.substring(1, text.length()-1));}}return false;}public static void main( String args[] ) {String input1 = "hello";String input2 = "dadad";boolean answer1 = isPalindrome(input1);boolean answer2 = isPalindrome(input2);System.out.println("Is " + input1 + " a Palindrome? = " + answer1);System.out.println("Is " + input2 + " a Palindrome? = " + answer2);}}
Understanding the Code
Every recursive code has two methods: the recursive method and the main method.
Driver Method
The ...