import java.util.*;
public class Fin4 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a word to check if it is a palindrome: ");
String word = in.nextLine();
word = word.replaceAll("[{}!@#$%^&.,' ]", "");
word = word.substring(0);
String reverse = "";
for(int i=word.length()-1;i>=0;i--)
reverse+=word.charAt(i);
if(word.equalsIgnoreCase(reverse))
System.out.print(word + " is a palindrome.");
else
System.out.print(word + " is not a palindrome.");
}
}
For example Enter a word to check if it is a palindrome: Madam, I'm adam The output should be -> Madam, I'm adam is a palindrome but my output is -> MadamImadam is a palindrome