public class Palindrome { public static void main (String[] argv) { String str = "redder"; System.out.println ( str + " " + checkPalindrome(str,0) ); str = "river"; System.out.println ( str + " " + checkPalindrome(str,0) ); str = "neveroddoreven"; System.out.println ( str + " " + checkPalindrome(str,0) ); } static String checkPalindrome (String str, int level) { // Two bottom out cases: if ( (str.length() == 0) || (str.length() == 1) ) { return "is a palindrome"; } if ( str.charAt(0) != str.charAt(str.length()-1) ) { return "is not a palindrome"; } // First and last letters matched. Remove them and check remaining recursively. String nextStr = str.substring (1, str.length()-1); return checkPalindrome (nextStr, level+1); } }