Check a String is palindrom or not
import java.io.*;
class palindrom
{
   public static void main(String args[])throws IOException
   {
       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
       System.out.println(" Enter a String ");
       String s =  br.readLine();
       int l=s.length();
       String x = "";
       int ch;
       ch=0;
       for(int i=l-1;i>=0;i--)
       {
           x=x+s.charAt(i);
       }
       if(x.compareTo(s)==0)
       System.out.println(" its A palindrom");
       else
       System.out.println(" its not a palindrom ");
   }
}
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment