Palindrome



If the given string is equal to the reverse of the string means that is called Palindrome.



Example-1:


Input    : s = "MOM"
Output   : Palindrome   
Explain  : s = "MOM" reverse String = "MOM".Both are Equal.So it's polindrome.


Example-2:


Input    : s = "BAT"
Output   : Not a palindrome  
Explain  : s = "BAT" reverse String = "TAB".Both are not Equal.So it's not a polindrome.   







Solution




public class Main
{
    public static void main(String[] args) 
    {
        String s = "mam";

        String reverse = "";

        for(int i = s.length()-1; i >= 0; i--) 
        {
            reverse = reverse + s.charAt(i);
        }

        if(s.equals(reverse))
        {
            System.out.print("Palindrome");
        }

        else
        {
            System.out.print("Not a Palindrome");
        }
    }
}
n = "mam"

a = n[::-1]

if(n==a):

    print("Palindrome")

else:

    print("Not a Palindrome")



Output



Palindrome