import java.util.Scanner; public class ReverseIt { public static void main(String[] args) { Scanner console = new Scanner(System.in); System.out.print("Enter a word: "); String phrase = console.nextLine(); System.out.print("\"" + phrase + "\""); phrase = removeSpaces(phrase); String wordReverse = Reverse(phrase); if (phrase.equalsIgnoreCase(wordReverse)) { System.out.println(" is a palindrome."); } else { System.out.println(" is not a palindrome."); } } //--------------------------------------- public static String Reverse (String s) { String newS = ""; for (int i = s.length()-1; i >= 0 ; i--) { newS = newS + s.charAt(i); } return newS; } //------------------------------------------------ public static String removeSpaces(String phrase) { String newPhrase = ""; for (int i = 0; i < phrase.length(); i ++) { if (isLetter(phrase.charAt(i))) { newPhrase += phrase.charAt(i); } } return newPhrase; } //-------------------------------------- public static boolean isLetter(char c) { if ('A' <= c && c <= 'Z') { return true; } else if ('a' <= c && c <= 'z') { return true; } else { return false; } // return (('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z')); } }