Package test; public class main {public static void main (string [] ARGs) {// defines some variables for formatting the output. Double D = 345.678; string S = "Hello! "; Int I = 1234; //" % "indicates formatted output. The content after" % "is the format definition. System. Out. printf ("% F", d); // "F" indicates formatting the output floating point number. System. out. println (); system. out. printf ("% 9.2f", d); // 9 in "9.2" indicates the length of the output, and 2 indicates the number of digits after the decimal point. System. Out. println (); system. Out. printf ("% + 9.2f", d); // "+" indicates that the output number carries a positive or negative number. System. Out. println (); system. Out. printf ("%-9.4f", d); // "-" indicates the left alignment of the number of outputs (right alignment by default ). System. out. println (); system. out. printf ("% +-9.3f", d); // "+-" indicates that the number of outputs carries positive and negative signs and is left aligned. System. Out. println (); system. Out. printf ("% d", I); // "D" indicates the output of a decimal integer. System. Out. println (); system. Out. printf ("% O", I); // "O" indicates the output of an octal integer. System. Out. println (); system. Out. printf ("% x", I); // "D" indicates the hexadecimal integer. System. Out. println (); system. Out. printf ("% # X", I); // "D" indicates the integer with the hexadecimal mark. System. Out. println (); system. Out. printf ("% s", S); // "D" indicates the output string. System. out. println (); system. out. printf ("output a floating point: % F, an integer: % d, a string: % s", D, I, S); // multiple variables can be output, pay attention to the sequence. System. out. println (); system. out. printf ("string: % 2 $ S, % 1 $ D hexadecimal number: % 1 $ # X", I, S ); // "x $" indicates the number of variables .}}