Thursday 13 June 2013

program to check that given number is palindrom or not

// simple_check_given_number_palindrom_or_not

import java.io.*;
class simple_check_given_number_palindrom_or_not
{
    public static void main(String args[])
    {
        int n,no,rem,rev=0;
        try
        {
            DataInputStream cin=new DataInputStream(System.in);
            System.out.println("Enter a number to check it is palindrom or not");
            n=Integer.parseInt(cin.readLine());
            no=n;

            while(no!=0)
            {
                rem=no%10;
                rev=rev*10+rem;
                no=no/10;
            }

            if(rev==n)
            {
                System.out.println(n+" is palindrom ");
            }
            else
            {
                System.out.println(n+" is not palindrom ");
            }
        }
        catch(Exception e)
        {
            System.out.println("wrong input");
        }
    }
}

No comments: