Section 2.4 Displaying Text with printf

System.out.printf method (p. 43; f means “formatted”) displays formatted data.

• Method printf’s first argument is a format string (p. 44) containing fixed text and/or format specifiers. Each format specifier (p. 44) indicates the type of data to output and is a placeholder for a corresponding argument that appears after the format string.

• Format specifiers begin with a percent sign (%) and are followed by a character that represents the data type. The format specifier %s (p. 44) is a placeholder for a string.

• The %n format specifier (p. 44) is a portable line separator. You cannot use %n in the argument to System.out.print or System.out.println; however, the line separator output by System.out.println ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.