Skip to content
Programming101
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programming101
Programmingoneonone

HackerRank Java String Reverse problem solution

YASH PAL, 31 July 2024

In this HackerRank Java string Reverse problem in the java programming language you have Given a string A, print Yes if it is a palindrome, print No otherwise.

HackerRank Java String Reverse problem solution

HackerRank java string reverses problem 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. */
        System.out.println( A.equals( new StringBuilder(A).reverse().toString()) ? "Yes" : "No" );
        
    }
}

Second 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();
        boolean valid = true;
        
        for(int i = 0; i < (A.length() / 2); i++) {
            if(A.charAt(i) != A.charAt((A.length() - 1) - i)) {
                valid = false;
                break;
            } // end if
        } // end for(i)
        
        if(valid) System.out.println("Yes");
        else System.out.println("No");
    } // end main
} // end class

The solution in java8 programming.

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 reverse = new StringBuilder(A).reverse().toString();
    if (A.equals(reverse)) {
      System.out.println("Yes");
    }
    else {
      System.out.println("No");
    }
  }
}
coding problems solutions Hackerrank Problems Solutions Java Programming Tutorials

Post navigation

Previous post
Next post

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes