import java.util.*; public class Assign1 { static Scanner in = new Scanner(System.in); public static void main (String [] args) { String line = getInputLine(); while (!isEmptyLine (line)) { if (isPalindrome (line)) System.out.println ("\"" + line + "\" is a palindrome and a " + getPalType (line)); else System.out.println ("\"" + line + "\" is not a palindrome"); line = getInputLine(); } System.out.println ("End of program"); } private static String getInputLine () { System.out.print("Enter a line of input: "); String inputString = in.nextLine(); return inputString; } private static boolean isEmptyLine (String str) { boolean ifEmpty = false; if(str == null) { ifEmpty = true; return ifEmpty; } else return ifEmpty; } private static boolean isPalindrome (String str) { int left = 0; int right = str.length()-1; boolean okay = true; while(okay && left < right) { char ch1 = str.charAt(left); if((!Character.isDigit(ch1) && !Character.isAlphabetic(ch1))) { left++ ; } else { char ch2 = str.charAt(right); if ((!Character.isDigit(ch2) && !Character.isAlphabetic(ch2))) { right-- ; } else { ch1 = Character.toUpperCase(ch1); ch2 = Character.toUpperCase(ch2); if (ch1 == ch2) { left++ ; right-- ; } else { okay = false; } } } } return okay; } private static String getPalType (String str) { int count = 0; String palType = ""; for(int index = 0; index <= str.length()-1; index ++) { if(str.charAt(index) < ':' && str.charAt(index) > ' ' ) if(str.charAt(index) == ' ') palType = "Phrase"; count++; } if (palType == "Phrase") return palType ; if (count == str.length()) return "Number" ; else return "Word" ; } }