O'Reilly logo

Java™ How To Program (Early Objects), Tenth Edition by Harvey Deitel, Paul Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

2.4 Displaying Text with printf

The System.out.printf method (f means “formatted”) displays formatted data. Figure 2.6 uses this method to output on two lines the strings "Welcome to" and "Java Programming!".

 1   // Fig. 2.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 class Welcome4

Welcome toJava Programming!

Fig. 2.6 | Displaying multiple lines with method System.out.printf.

Lines 9–10 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required