Java String Reverse-HackerRank Solution

0

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

Given a string A, print Yes if it is a palindrome, print No otherwise.




Constraints


 A will consist of at most lower case English letters.


Sample Input


madam


Sample Output


Yes


Solution


import java.io.*;

import java.util.*;


public class Solution {


    public static void main(String[] args) {

        

        Scanner sc=new Scanner(System.in);

        String A=sc.next();

        String reverse="";

        int length = A.length();

        for(int i =length-1;i>=0;i--){

            reverse = reverse+A.charAt(i);

        }

        if(reverse.equals(A)){

            System.out.println("Yes");

        }

        else{

            System.out.println("No");

        }

       

        /* Enter your code here. Print output to STDOUT. */

        

    }

}


Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.
Post a Comment (0)
Our website uses cookies to enhance your experience. Learn More
Accept !