Algorithm


Problem Name: Java String Reverse

Problem Link: https://www.hackerrank.com/challenges/java-string-reverse/problem?isFullScreen=true

In this HackerRank Functions in Java programming problem solution,

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

 

 

 

 

Code Examples

#1 Code Example with Java Programming

Code - Java Programming


import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        
        Scanner sc=new Scanner(System.in);
        String A=sc.next();
        String B = new StringBuilder(A).reverse().toString();
                
        if(A.equals(B))
            System.out.println("Yes");
        else
            System.out.println("No");
    }
}

Copy The Code & Try With Live Editor
Advertisements

Demonstration


Previous
[Solved] Constructing a Number solution in Hackerrank - Hacerrank solution C, C++, C#, java, js, Python