Java String Reverse Hacker Rank Solution

Hello coders, In this post, you will learn how to solve Java String Reverse Hacker Rank Solution. This problem is a part of the Java programming series. 

One more thing to add, don’t straight away look for the solutions, first try to solve the problems by yourself. If you find any difficulty after trying several times, then look for the solutions.

Java String Reverse Hacker Rank Solution
Java String Reverse Hacker Rank Solution

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.


  • A will consist at most 50 lower case english letters.

Sample Input


Sample Output


Java String Reverse Hacker Rank Solution

import java.util.Scanner;
public class Solution {
    public static void main(String[] args) {
        /* Read input */
        Scanner scan = new Scanner(;
        String str = scan.nextLine();
        /* 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 Chase2Learn. This tutorial is only for Educational and Learning purposes. Authority if any of the queries regarding this post or website fill the following contact form thank you.

Sharing Is Caring

Leave a Comment