Sunday 24 March 2019

Java String Reverse HackerRank Solution in Java

Problem:-

A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward.(Wikipedia)

Given a string , print Yes if it is a palindrome, print No otherwise.
Constraints
  •  will consist 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();
System.out.println( A.equals( new StringBuilder(A).reverse().toString()) ? "Yes" : "No" );
}
}



No comments:

Post a Comment

Error While embed the video in Your website page

Error:- Refused to display '<URL>' in a frame because it set 'X-Frame-Options' to 'sameorigin Solution:- if ...