HackerRank Java- String Reverse

Given a string A, print Yes if it is a palindrome, print No otherwise.

  1. import java.io.*;
  2. import java.util.*;
  3. public class Solution {
  4. public static void main(String[] args) {
  5. /* Read input */
  6. Scanner scan = new Scanner(System.in);
  7. String str = scan.nextLine();
  8. scan.close();
  9. /* Reverse string and compare to original */
  10. String reversed = new StringBuilder(str).reverse().toString();
  11. System.out.println(str.equals(reversed) ? "Yes" : "No");
  12. }
  13. }
Please click on the like button if it worked

Solution not working or have any suggestions? Please send an email to [email protected]

donate a cup of tea :)

Join Our Facebook Group

Share this solution


Codesadda.com is your home of programming solutions, tutorials, video tutorials and much more. Sign Up for our weekly newsletter to get update about new content.

Like us on Facebook | Connect with us on LinkedIn | Subscribe our Channel on Youtube