55.Print NOT palindrome Strings

55

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


Comments

  1. class Notpalindrome {
    public 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;
    }
    }

    ReplyDelete

Post a Comment

Popular posts from this blog

Strings

Arrays