
public class Palindrome
{
   public static void main(String[] args) 
   {
      String  s = "racecar";
      boolean ans;

      ans = isPalindrome(s);
   }

   public static boolean isPalindrome(String w)
   {
      boolean helpSol;
      boolean mySol;

      if ( w.length() <= 1 )
      {  // base cases
         return true;
      }
      else
      {
         int lastPos = w.length() - 1;
         String help = w.substring(1, lastPos);
         helpSol = isPalindrome( help );

         mySol = (w.charAt(0) == w.charAt(lastPos)) && helpSol;

         return mySol;
      }
   } 
}

