/** * */ /** * @author arau-chaplin * */ //******************************************************************* // // Palindromes.java In Text Application // // Authors: Lewis and Loftus // // Classes: Palindromes // Palindrome_Tester // //******************************************************************* //------------------------------------------------------------------- // // Class Palindromes demonstrates recursive calls. // // Methods: // // public static void main (String[] args) // //------------------------------------------------------------------- public class Palindromes { //=========================================================== // Creates a Palindrome_Tester object, and tests several // strings. //=========================================================== public static void main (String[] args) { Palindrome_Tester tester = new Palindrome_Tester(); System.out.println ("radar is a palindrome? " + tester.ptest ("radar")); System.out.println ("abcddcba is a palindrome? " + tester.ptest ("abcddcba")); System.out.println ("able was I ere I saw elba is a palindrome? " + tester.ptest ("able was I ere I saw elba")); System.out.println ("hello is a palindrome? " + tester.ptest ("hello")); System.out.println ("abcxycba is a palindrome? " + tester.ptest ("abcxycba")); } // method main } // class Palindromes //------------------------------------------------------------------- // // Class Palindrome_Tester contains a method to test to see if // a string is a palindrome. // // Methods: // // public boolean ptest (String str) // //------------------------------------------------------------------- class Palindrome_Tester { //=========================================================== // Uses recursion to perform the palindrome test. //=========================================================== public boolean ptest (String str) { boolean result = false; if (str.length() <= 1) result = true; else if (str.charAt (0) == str.charAt (str.length()-1)) result = ptest (str.substring (1, str.length()-1)); return result; } // method ptest } // class Palindrome_Tester