code: 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('0');
      }
      if (num != 0) {
        sb.append(num);
      }
    }
docs: Appends a zero-padded number to a string builder.