Java String Reverse HackerRank Solution

Hello Programmers, In this post, you will know how to solve the Java String Reverse HackerRank Solution. This problem is a part of the HackerRank Java Programming Series.

Java String Reverse HackerRank Solution
Java String Reverse HackerRank Solutions

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

Java String Reverse HackerRank Solutions

Ezoicreport this adProblem :

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 HackerRank Solutions

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 BrokenProgrammers. This tutorial is only for Educational and Learning purposes.

Next: Java Anagrams HackerRank Solution

Sharing Is Caring

Leave a Comment

Ezoicreport this ad