55.Print NOT palindrome Strings
Problem of the Day:
From the input sentence given, find the strings which are not palindrome and print it.
-
Input: he knows malayalam
Output: he knows
- Input 2:
Input: a b c abc cba
Output: abc cba
-
Input: he knows malayalam
Output: he knows - Input 2:
Input: a b c abc cba
Output: abc cba
class Notpalindrome {
ReplyDeletepublic static void main(String[] args) {
String s1 = "he knows malayalam";
String[] words = s1.split(" ");
for (String word : words) {
if (!isPalindrome(word)) {
System.out.print(word + " ");
}
}
}
static boolean isPalindrome(String word) {
int left = 0, right = word.length() - 1;
while (left < right) {
if (word.charAt(left) != word.charAt(right)) {
return false;
}
left++;
right--;
}
return true;
}
}