First take the words of str in an array. Then check whether the words in the forward order and the reverse order are same.
String[] words = str.split(" "); //splits at spaces
boolean flag = true;
int i, last = words.length - 1;
for(i = 0; i <= last/2; i++){
if(!words[i].equalsIgnoreCase(words[last - i])){
flag = false;
System.out.printf("NOT PALINDROME");
break;
}
}
if(flag)
System.out.printf("PALINDROME");
0
solved How to check in Java whether the input Sentence is of palindrome(not exactly, but like that) in nature or not?