Java Output Formatting

  • + 6 comments

    Here's a breakdown of the format string "%-15s%03d\n":

    %-15s: - means left-justified, 15 means minimum width of 15 characters, s means a string value will be inserted here %03d: 0 means pad with leading zeroes, 3 means minimum width of 3 digits, d means an integer value will be inserted here \n: newline character The first argument s1 is a string value to be formatted, and it will be left-justified and padded with spaces to a minimum width of 15 characters.

    The second argument x is an integer value to be formatted, and it will be padded with leading zeroes to a minimum width of 3 digits.