Tuesday, 8 October 2013

PALINDROMIC NUMBER - CODE IN JAVA

Here is the source code that checks whether a number is palindrome or not. A number is palindrome if it is equal to the reverse of itself. For example, 12321 is a palindrome.
SOURCE CODE:-
/***************************************************************************/


import java.util.Scanner;
class palindromicnumber
{
       public static void main(String[]args)
       {
              Scanner s=new Scanner(System.in);
              int num=s.nextInt();
              int rev=0,cnum=num;
              //getting the reverse of the number in rev
              while(cnum!=0)
              {
                     rev=rev*10+cnum%10;
                     cnum/=10;
              }
             
              if(rev==num)
                     System.out.println("THE NUMBER YOU ENTERED IS A PALINDROMIC NUMBER");
              else
                     System.out.println("THE NUMBER YOU ENTERED IS NOT A PALINDROMIC NUMBER");
       }
}

/***************************************************************************/

No comments:

Post a Comment