A.4 Displaying Text with printf

The System.out.printf method displays formatted data. Figure A.6 uses this method to output the strings "Welcome to" and "Java Programming!". Lines 9–10 call method System.out.printf to display the program’s output. The method call specifies three arguments—they’re placed in a comma-separated list.

Fig. A.6 Displaying multiple lines with method System.out.printf

Computer code and output. The code has 12 lines.

Lines 9–10 represent only one statement. Java allows large statements to be split over many lines. We indent line 10 to indicate that it’s a continuation of line 9.

Method printf’s first argument is a format string that may ...

Get Android How to Program, 3/e 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.