Java String Reverse – Hacker Rank Solution

 



Problem :

A palindrome is a word, phrase, number, or other sequence 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 at most 50 lower case english letters.

Sample Input

madam

Sample Output

Yes


Java String Reverse – Hacker Rank Solution

Code:

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        /* Read input */
        Scanner scan = new Scanner(System.in);
        String str = scan.nextLine();
        scan.close();
        
        /* Reverse string and compare to original */
        /* If a String is equivalent to itself when reversed, it's a palindrome */
        
        String reversed = new StringBuilder(str).reverse().toString();
        System.out.println(str.equals(reversed) ? "Yes" : "No");
    }
}

Disclaimer: The above Problem (Java String Reverse) is generated by Hackerrank but the Solution is Provided by MultiplexCoder. This tutorial is only for Educational and Learning purposes.

Tags:    hackerrank Java solutions | Functions Discussions | java | HackerRank | student analysis java hackerrank solution | challenges java hackerrank solution | hackerrank java basic certification solutions | hackerrank-java certification solutions | basic data types hackerrank solution in java | hackerrank java questions and answers | hackerrank java certification solutions | hackerrank java coding questions and answers | hackerrank-java certification solutions github | hackerrank java tutorial | hackerrank java interview questions | hackerrank java compiler | welcome to java hackerrank solution | 2021

Previous
Next Post »