Hi friends!
This part of the code is done by one of my teacher and the codes are actually the answer of the following question:
"Write a recursive method that checks if a String sent in as parameter is a palindrome
(Palindrome = Reads the same from both left and right. I.e. “anna” and “xyzyx”). The method
shall return true if the parameter is a palindrome, false otherwise.
The method signature shall look like this:
public boolean isPalindrome(String s)"
But I have no idea how the code is working here , specially the two if statements. Plz anyone explain to me, thanks in advance!
private boolean isPalindrome(String s) { if (s.length() == 0 || s.length() == 1) { return true; } else if (s.charAt(0) == s.charAt(s.length()-1)){ return isPalindrome(s.substring(1, s.length()-1)); } return false; }