Java String Reverse | HackerRank Solution

Hello coders, today we are going to solve Java String Reverse HackerRank Solution.

Java String Reverse

Contents

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.

Read : How to reverse string in Java ?

Constraints

A will consists at most 50 lower case English letter.

Sample Input
 madam
Sample Output
 Yes

Solution – Java String Reverse

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();
        /* Enter your code here. Print output to STDOUT. */
        String rev="";
        for(int i=A.length()-1;i>=0;i--)
        {
            rev = rev+A.charAt(i);
        }
        if(rev.equals(A))
         System.out.print("Yes");
         else
         System.out.print("No");
        
    }
}

Disclaimer: The above Problem ( Java String Reverse ) is generated by Hacker Rank but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

Your email address will not be published.