Question
1.19 Lab1c: EasyAsPie Introduction There are subtle, but important, differences in the println() and print() methods. For this assignment, you will explore these differences by
1.19 Lab1c: EasyAsPie
Introduction
There are subtle, but important, differences in the println() and print() methods. For this assignment, you will explore these differences by outputting variations of the phrase "Easy as pie."
The following procedures should be done in succession, thus producing a single output for all print statements:
Task
-
To begin, Type:
System.out.println("Easy as pie"); System.out.print("Easy as pie");
-
This time, type the same two print statements but inverted:
System.out.print("Easy as pie"); System.out.println("Easy as pie");
Notice that the print() method does not end the line and return to the beginning of the next line. Thus the last three statements are printed to the console on the same line. The println() method in the last statement finally ended the line after printing the contents of the parenthesis.
-
Sometimes you just want a blank line. Try typing:
System.out.println("");
The "" is a blank string, so nothing is printed and the line ends.
-
The println() method doesn't need a String to output in order to use it.
Type this, notice the parenthesis are left empty:
System.out.print("I am a place holder, the line below can be highlighted!"); System.out.println();
-
In opposition, the print() method cannot be called with empty parenthesis (since it's sole use is to output data to the console, it wouldn't make sense to leave it blank regardless). Thus, if you wish to create a new line using print(), you will need to use escape character previously used in Lab1b.
Try:
System.out.print("This line below the placeholder was once blank, now it's not!"); System.out.print( );
This code will cause a syntax error because print() expects a String. Change into a String by surrounding it in "".
-
Use a print statement to create a blank line. This will leave a blank line between the outputs of step 5 and step 6. All following steps should be separated like this.
Now print the statement "Easy as pie" with only one word on each line.
Expected output for 5 and 6:
I am a place holder, the line below can be highlighted! This line below the placeholder was once blank, now it's not! Easy as pie
-
Using only println(), output:
I want PIE!!!!
-
Using exactly 5 print() methods, output:
ThePie is all GONE?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started