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.

 1   // Fig. A.6: Welcome4.java 2   // Displaying multiple lines with method System.out.printf. 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      } // end method main12   } // end ...

Get Android™ How to Program, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.