Tuesday, October 16, 2012

Palindrom Number

See this to view the content of this question.
 
Java Code:


   public  static boolean isPalindrome(int x)
    {
      if ( x < 0 )
         return false;
     
      int count = (int) Math.floor( Math.log10(x)) + 1;
     
      if (count < 2)
          return true;
    
      int tmp = (int) Math.pow(10, count -1);
      int start = 10;
     
      while ( count > 1)
      {
         if ( x%start != x/tmp)
             return false;
        
         x =( x - (x/tmp * tmp) - (x%start *(start/10)) ) /10;
        
         tmp = tmp/100;
        
         count -= 2;
        
      }
     
    return true;
   
    }

No comments:

Post a Comment