Exercise
Function Palindrome, recursive
Objetive
Write a java recursive function to say whether a string is symmetric (a palindrome). For example, "RADAR" is a palindrome.
Example Code
public class Main
{
public static boolean IsPalindrome(String text)
{
if (text.length() <= 1)
{
return true;
}
else
{
if (text.charAt(0) != text.charAt(text.length() - 1))
{
return false;
}
else
{
return IsPalindrome(text.substring(1, 1 + text.length() - 2));
}
}
}
public static void main(String[] args)
{
System.out.println(IsPalindrome("radar"));
System.out.println(IsPalindrome("pato"));
}
}