Java Output Formatting

  • + 0 comments

    Basically every %... is gonna be replaced by one of the arguments of printf. What is after the % sign is a format specifier.

    In %-15s:

    • means: left-justified 15 means: if the result is less than 15 characters long, add spaces until it is 15 characters long s means: convert the parameter into a string with toString and use the result In %03d:

    0 means: pad with 0s instead of spaces 3 means: make it at least 3 characters long d means: the argument will be an integer number, format it as a base-10 number. %n is the same as \n on *NIX or \r\n on Windows.

    You will get more info here: https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html#syntax