Thursday, 22 January 2015

Program in java to check whether a String is palindrome or not

import java.util.*;
public class Palindrome
{
   public static void main(String args[])
   {
      String original, reverse = "";
      Scanner in = new Scanner(System.in);
 
Program in java to check whether a String is palindrome or not       System.out.println("Enter a string to check palindrome");
      original = in.nextLine();
 
      int length = original.length();
 
      
     
      for ( int i = length - 1 ; i >= 0 ; i-- )
         reverse = reverse + original.charAt(i);
 
      if(reverse.equals(original))
      System.out.println("Yes String is palindrome");
      else
       System.out.println("NO String is not palindrome"); 
   }
}

No comments:

Post a Comment