Java Program to check whether the entered String is a Palindrome or not - HackerRank

 


// Program by Akash Tripathi (@proakash256) 
import java.util.*;
public class String_palindrome {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        String s1 = sc.next();
        String s2 = "";
        sc.close();
        for(int i = (s1.length() - 1); i >= 0i = i - 1)
        {
            s2 = s2 + s1.charAt(i);
        }
        if(s1.compareTo(s2) == 0)
            System.out.println("Yes");
        else
        System.out.println("No");
    }
}

Comments