Palindrome No.

Input any number and check if it is a Palindrome Number or not. A number that reads the same from both the ends (Hint: 121 = 121)

import java.io.*;
class Palindrome
{
   public static void main(String args[])throws IOException
   {
    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter a number : ");
    int n=Integer.parseInt(br.readLine());
    int rev=0,dig;
    int copy=n;
    while(n>0)
    {
        dig = n % 10;
        rev = rev*10 + dig;
        n = n/10;
    }
    if(rev==copy)
        System.out.println("The number is a Palindrome");
    else
        System.out.println("The number is Not a Palindrome");
    }
}

No comments:

Post a Comment