DEV Community

Rajesh Mishra
Rajesh Mishra

Posted on • Originally published at onlinetutorials.tech on

Palindrome Program in Java for Reversing String


Palindrome is nothing but any number or a string which remains unchanged when it is reversed. For example: 121 or RAR. It is observable that letters form reflect images on turn around.

class PalindromeProgramInJavaForReversingString{
      public static void checkPalindrome(String s){
      // Reversing given string using StringBuffer class
      String reverse = new StringBuffer(s).reverse().toString();

      // checks whether the string is palindrome or not
      if (s.equals(reverse)){
          System.out.println("Yes, it is a palindrome");
       }else{
          System.out.println("No, it is not a palindrome");
       }
     }
     public static void main (String[] args)throws java.lang.Exception{
        checkPalindrome("madam");
     }
 }

Learn More about Palindrome:


Top comments (0)