Q:

Java Program to check a string is palindrome or not?

0

Java Program to check a string is palindrome or not?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.");
 
   }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now