JAVA: How do I determine if the input is a palindrome? : <p>Please use the method below. </p>

<p>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.</p>

<p>I can't figure it out.</p>

<pre><code>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&gt;=0; i--) {
        reverse +=word.charAt(i);


        }

        for(int i=0; i&lt;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");```

</code></pre>
