AP Computer Science Java: Lesson 1.4b
Input and Output - Basic Output

Lesson 1.4b - Basic Output
Purpose: To learn how to display information with the System.out statement

Program Output
Displaying information is a very important feature of computer programs. Output statements enable us to see the data that is stored in variables. The most basic form of output is the use of the System.out statement from the pre-defined java.io package. Let's explore several uses of this statement.

There are two main ways that you will use the System.out statement, System.out.print and System.out.println (read this as print line) . Both of these statements display information in the same way. It's what they cause to happen after the display takes place is what makes them different. Let's see some examples.

The code...


will produce the following output:




will produce:


The difference between print and println is that println moves the cursor down to the next line after output, whereas the print statement stays on the same line after output. Typically we use print for prompt statements and println for other output. However, there will be other uses of print that will come up from time-to-time. For now, choose the right statement for the task at hand.


© DanShuster.com