Palindrome String In Java

What is Palindrome?

A Palidrome string is a string where if we reverse the string, the word will be same.

A palindrome is a word, number, phrase, or other sequence of characters which reads the same backward as forward.

Example: madam, refer, redivider

The logic in Java for implementation is very simple.,

    • Reverse the string
    • Compare the reversed string with the input string,
      • If it is same, then Palidrome String
      • Else not a Palindrome String.

    Output:

    Input String: abcdcba , Reversed String: abcdcba
    Is String 1 Palindrome : true
    Input String: abcde , Reversed String: edcba
    Is String 2 Palindrome : false
    Input String: madam , Reversed String: madam
    Is String 3 Palindrome : true
    Input String: refer , Reversed String: refer
    Is String 4 Palindrome : true
    Input String: hello , Reversed String: olleh
    Is String 5 Palindrome : false

    One thought on “Palindrome String In Java

    Comments are closed.