"-" Left justify this argument
"+" Include a sign (+ or -) with this argument
"0" Pad this argument with zeroes
"," Use locale-specific grouping separators (i.e., the comma in 123,456)
"(" Enclose negative numbers in parentheses
width This value indicates the minimum number of characters to print.
precision Formatting a floating-point number,
precision indicates the number of digits to print after the decimal point.
conversion The type of argument you'll be formatting. You'll need to know:
b boolean
c char
d integer
f floating point
s string
public class MainClass {
public static void main(String[] argv) {
int i1 = -123;
int i2 = 12345;
System.out.printf(">%1$(7d< \n", i1);
System.out.printf(">%0,7d< \n", i2);
System.out.format(">%+-7d< \n", i2);
System.out.printf(">%2$b + %1$5d< \n", i1, false);
}
}
> (123)<
>012,345<
>+12345 <
>false + -123<