Skip to main content
ICT
Lesson A7 - Simple I/O
 
Main   Previous Next
 

B. Multiple Line Stream Output Expressions page 4 of 7

  1. We have already used examples of multiple output statements such as:

    System.out.println("The value of sum = " + sum);

  2. When the length of an output statement exceeds one line of code, it can be broken up several different ways:

    System.out.println("The sum of " + num1 + " and " + num2 +
                       " = " + (num1 + num2));

    or

    System.out.print("The sum of " + num1 + " and " + num2);
    System.out.println( " = " + (num1 + num2));

  3. You cannot break up a String constant and wrap it around a line.

System.out.print("A long string constant must be broken
up into two separate quotes. This will NOT work.");

System.out.print("A long string constant must be broken up"
             + " into two separate quotes. This will work.");

 

Main   Previous Next
Contact
 © ICT 2006, All Rights Reserved.