Java Program to find a String is Pallindrome or not


You have been given a String “S” and you have to find and print whether this string is a palindrome or not. If yes, print “YES” (without quotes), else print “NO” (without quotes).

Input Format
The first and only line of input contains the String S. The String shall consist of lowercase English alphabets only.

Output Format
Print the required answer on a single line.


class TestClass {
    public static void main(String args[] ) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(;
        String S = br.readLine();
        char[] ch = new char[S.length()];

        for(int i=0;i<S.length();i++) {
            ch[i] = S.charAt(i);
        String T = "";
        for(int i=S.length()-1;i>=0;i--) {
        if(S.equals(T)) {
        } else {

To solve this program on HackerEarth click here.

To check more programs click here.

Leave a Reply

Your email address will not be published. Required fields are marked *