Palindrome

Description:

Write a java program that checks whether a given string is a palindrome or not Test Case 1 Input (stdin) madam Expected Output palindrome Test Case 2 Input (stdin) won Expected Output not palindrome

Program :

import java.io.*;

import java.util.Scanner;

public class TestClass {

public static void main(String[] args) {

String a,b = "";

        Scanner s = new Scanner(System.in);

       

        a = s.nextLine();

        int n = a.length();

        for(int i = n - 1; i >= 0; i--)

        {

            b = b + a.charAt(i);

        }

        if(a.equalsIgnoreCase(b))

        {

            System.out.println("palindrome");

        }

        else

        {

            System.out.println("not palindrome");

        }

}

}