Sunday, 20 July 2014

Java Program to check given string is palindrome or not

Program

 import java.lang.*;
 import java.util.*;
 class palindrome
 {
   public static void main(String args[])
   {
     StringBuffer s1=new StringBuffer(args[0]);
     StringBuffer s2=new StringBuffer(s1);
     s1.reverse();
     System.out.println("Given string : "+s2);
     System.out.println("Reverse string : "+s1);
     String s3=s1.toString();
     String s4=s2.toString();
     if(s3.equals(s4))
      System.out.println("Given String is Palindrome");
     else
      System.out.println("Given String is not Palindrome");
   }
 }


Result

  Given string : liril
  Reverse string : liril
  Given String is Palindrome


No comments:

Post a Comment