private static void appendInt ( StringBuilder sb , int num , int numDigits ) { if ( num < 0 ) { sb . append ( ' ' ) ; num = - num ; } int x = num ; while ( x > 0 ) { x /= 10 ; numDigits -- ; } for ( int i = 0 ; i < numDigits ; i ++ ) { sb . append ( ' ' ) ; } if ( num != 0 ) { sb . append ( num ) ; } }
Appends a zero - padded number to a string builder .