2.4. Displaying Text with printf
Java SE 5.0 added the System.out.printf method for displaying formatted data—the f in the name printf stands for “formatted.” Figure 2.6 outputs the strings "Welcome to" and "Java Programming!" with System.out.printf.
Figure 2.6. Displaying multiple lines with method System.out.printf.
1 // Fig. 2.6: Welcome4.java 2 // Printing multiple lines in a dialog box. 3 4 public class Welcome4 5 { 6 // main method begins execution of Java application 7 public static void main( String args[] ) 8 { 9 System.out.printf( "%s\n%s\n", 10 "Welcome to", "Java Programming!" ); 11 12 } // end method main 13 14 } // end class Welcome4
|
Lines 9–10
System.out.printf( "%s\n%s\n", "Welcome to", "Java ...
Get Java™ How to Program, Seventh 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.