Java

Program to check a string is palindrome or not?

Program to check a string is palindrome or not?
import java.util.*;
 
class demo1
{
   public static void main(String args[])
   {
      String before, after = ""; 
      Scanner in = new Scanner(System.in);
 
      System.out.println("Enter a string to check if it is a palindrome");
      before = in.nextLine();
 
      int l = before.length();
 
      for ( int i = l - 1; i >= 0; i-- )
         after = after + before.charAt(i);
 
      if (before.equals(after))
         System.out.println("Entered string is a palindrome.");
      else
         System.out.println("Entered string isn't a palindrome.");
 
   }
}
Nikhil Juneja

Passionate software developer and technical contributor at TutorialsLink.