Java String Reverse HackerRank Solution

Java String Reverse  HackerRank Solution

Java reverse string HackerRank Sollution,How to reverse string, Java interview questions
How to reverse a String in JAVA 

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

Problem

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();
        /* Enter your code here. Print output to STDOUT. */
        StringBuilder sb=new StringBuilder(A);
        sb.reverse();
        if(A.equals(sb.toString()))
        System.out.println("Yes");
        else
         System.out.println("No");
    }
}



So, Guys that was the solution of Java String Reverse  HackerRank Solution
 in Java. You can try out other ways to solve this question and can post the answer in comment section. String reverse, palindrome, anagrams are the common and very important topics which frequently come in TCS NQT, WIPRO NLTH and in COCUBES TESTS.So, you must check them out.Do, follow our blogs because we are upload a series of posts on TCS NQT QESTION PREPARATIONS and for WIPRO NLTH too.

If you have any question regarding the post ask me in Comment section.
And also give your solution for the question in the comment, Happy reading.


Post a Comment

0 Comments