• Yogeeta Paryani

JAVA | Check whether given String is Palindrome or not

To check whether the string is palindrome or not, we have to compared the string with the reverse of itself.

For Example 'LOL' is a palindrome string as position of each character remain same after reversing it.


import java.util.Scanner;
class ChkPalindrome
  public static void main(String args[])
     //Declaring temporary string
     String rev="";
     Scanner in=new Scanner(System.in);
     //Taking original String from user
     System.out.println("Enter a String to check:");
     String str=in.nextLine();
     // Storing length of String
     int n=str.length();
     //Reversing the String and storing into rev
     for(int i=n-1;i>=0;i--)

     //Now comparing whether str is equal to rev or not
/*using equalsIgnoreCase string method to ignoring the case considerations*/
       System.out.println( str+" is a palindrome.");

       System.out.println(str+" is not a palindrome.");


Enter a String to check:
LOL is a palindrome.

Enter a String to check:
GET is not a palindrome.

Happy Coding!

Follow us on Instagram @programmersdoor

Join us on Telegram @programmersdoor

Please write comments if you find any bug in the above code/algorithm, or find other ways to solve the same problem.

Follow Programmers Door for more.

#blog #strings #java #palindrome #learn #programming

52 views0 comments

Recent Posts

See All

        Contact Us


  • LinkedIn
  • Facebook
  • Instagram

©2023 by Programmers Door