Skip to main content
Lesson 4 - Simple I/O
Lesson MenuPreviousNext
  
Multiple Line Stream Output Expressions page 4 of 10

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

    System.out.println("The value of sum = " + sum);
  2. There will be occasions when the length of an output statement exceeds one line of code. This 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. This is not valid:

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

    However, this will work:

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

Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.