public static int numDigits ( int number ) { if ( number == 0 ) return 1 ; int adjustment = 0 ; if ( number < 0 ) { adjustment = 1 ; number = - number ; } return adjustment + ( int ) Math . log10 ( number ) + 1 ; }
Returns the number of digits in a number . E . g . 345 = 3 - 345 = 4 0 = 1