/* Name: Joseph Schuman Date: 1/28/2015 File: Chapter 5 Assignment Descripetion: Checks an inserted string to see if its a palindrome or not and output the result to the user. */ import java.util.Scanner; public class CPT236PalindromeCheck { public static void main(String[] args) { //Create a Scanner Scanner input = new Scanner(System.in); //Prompt user to enter a string System.out.print("Enter a string: "); String m = input.nextLine(); //Accept spaces and punctuation marks String n = m.replaceAll("[\\W]", ""); //Make input all lowercase String s = n.toLowerCase(); //The index of the first character in a string int low = 0; //The index of the last character in the string int high = s.length() - 1; boolean isPalindrome = true; while (low < high) { if (s.charAt(low) != s.charAt(high)) { isPalindrome = false; break; } low++; high--; } if (isPalindrome) System.out.println(m + " is a palindrome"); else System.out.println(m + " is not a palindrome"); } }