import javax.swing.JOptionPane; public class StringRecursion { public static void main(String[] args) { boolean done = false; do { String input = JOptionPane.showInputDialog(null, "Any String"); if (input == null) done = true; else System.out.println(input + (isPalindrome(input) ? " IS " : " IS NOT ") + "a Palindrome" ); } while (!done); } public static boolean isPalindrome(String str) { String testString = lettersOnly(str); return reverse(testString).equalsIgnoreCase(testString); //return symmetric( lettersOnly(str).toLowerCase() ); } public static String reverse(String str) { if (str.length() <=1) return str; return reverse(str.substring(1)) + str.charAt(0); } public static String lettersOnly(String str) { if (str.length() == 0) return ""; char firstChar = str.charAt(0); String remainder = lettersOnly( str.substring(1) ); if ( !Character.isLetter( firstChar ) ) return remainder; return firstChar + remainder; } private static boolean symmetric(String str) { if (str.length() <= 1) return true; int endIndex = str.length()-1; if ( str.charAt(0) != str.charAt(endIndex) ) return false; return symmetric( str.substring(1, endIndex) ); } }