Task 3 of 11 · 0 solved · 11 to go0%
You can read the problem, but answers are checked only for signed-in students. Sign in to answer →

1.1 Output — the print statement

Lesson

Your first program: output

The first thing a program does is show a result on the screen. In Java you print text with System.out.println(...). This notebook is about how that statement is built.


The four parts of a print statement

A print statement has four parts, and all are required: the command System.out.println, round parentheses, the text in double quotes, and a semicolon at the end.

System.out.println("Hello");

Miss any one part and the program will not run.


Worked example

System.out.println("Hello");
System.out.println("World");

Two statements print two lines: Hello then World. Each is built the same way.


▶ Try it: run this, then change something and run it again.



Which line correctly prints the word Hello?


What is missing from this line?

System.out.println("Hello")

Assemble a statement that prints Hi.


Fill the blank so the line prints the word Yes.


Click the part that ends the statement.


Type exactly what this program prints.

public class Main { public static void main(String[] a){
    System.out.println("Java");
    System.out.println("rocks");
}}