Java Program

Object:-Write a Program in java to check whether number is pallindrome or not.

class Palindrome
{
    public static void main(String...s)
    {
        int n,m,rev=0,i;
        System.out.println("Enter the number:");
        n=Integer.parseInt(s[0]);
        m=n;        
        while(n!=0)
        {
            i=n%10;
            rev=(rev*10)+i;
            n/=10;
        }        
        if(m==rev)
            System.out.println("nNumber is palindrome");
        else
            System.out.println("nNumber is not palindrome");
    }
}

Output

Enter the number:121
Number is palindrome
 

Explanation

A number is called palindrome if it is equal to its reverse.For example 121 is a palindrome while 123 is not palindrome.








You may also like: