Println’s Review#
These questions are to assess your understanding of printing in Java.
Question 1
True or False: The System.out.print
method displays text to the screen and inserts a new line.
See Answer
False!
Question 2
Which of the following is the correct syntax to output the message “Hello, world!”?
System.out.println(Hello, world!);
System.println("Hello, world!");
System.println.out('Hello, world!);
Out.system.println"(Hello, world!)";
System.out.println("Hello, world!");
See Answer
The correct syntax to output “Hello, world!” is:
System.out.println("Hello, world!");
Question 3
What series of System.out.print
and System.out.println
statements would produce the following output?
Several slashes are sometimes seen,
said Sally. I've said so. See?
Make sure to choose all options that produce the desired output.
Hint: For each print
and println
statement, track where your cursor is going to be at the end of that statement!
System.out.print("Several slashes are sometimes seen,"); System.out.print("said Sally. I've said so. See?");
System.out.println("Several slashes are sometimes seen,"); System.out.println("said Sally. I've said so. See?");
System.out.print("Several slashes "); System.out.print("are sometimes seen,"); System.out.println("said Sally. I've said so. See?");
System.out.print("Several slashes "); System.out.println("are sometimes seen,"); System.out.println("said Sally. I've said so. See?");
See Answer
Options 2 and 3 are correct!
Question 4
What is the output of the following series of System.out.print
and System.out.println
statements:
System.out.print("There's one thing every coder ");
System.out.println("must understand:");
System.out.println("The System.out.println command.");
Write it as you would see on the terminal. (i.e. no quotation marks!)
See Answer
There’s one thing every coder must understand: The System.out.println
command.
Explanation
First, we print out There's one thing every coder
but stay on the same line since it is just a print statement. Then, we print out must understand
: on the same line and then move to the next line because it is a println statement. Finally, we print out The System.out.println command.
and move to the next line.
Answer:
There's one thing every coder must understand:
The System.out.println command.