Please use the method below.
I am trying to get rid of all white spaces, punctuations and make everything lowercase. Then I want to see whether the string is a palindrome (same when read from the front and back.
I can't figure it out.
public static void main(String[] args) {
String word=null;
String reverse="";
Scanner console = new Scanner(System.in);
System.out.print("Please enter a word or a phrase:");
word = console.nextLine();
word=word.replaceAll("\\s+",""); //removes white space
word=word.replaceAll("[^a-zA-Z ]", ""); //removes all punctuation
word=word.toLowerCase();
for(int i=word.length()-1; i>=0; i--) {
reverse +=word.charAt(i);
}
for(int i=0; i<word.length(); i++) {
System.out.print(word);
if(word.charAt(i) != reverse.charAt(i)) {
System.out.println("Not a Palindrome");
}else {
System.out.println("Palindrome");```