There are subtle, but important, differences in the println() and print() method
ID: 3786289 • Letter: T
Question
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:
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 1. lo begin, Type: System.out.println Easy as pie System.out.print Easy as pie 2. 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 3. 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 4. 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() 5. 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 In 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 (In)Explanation / Answer
Lab1c.java
public class Lab1c {
public static void main(String[] args) {
System.out.println("Easy as pie");
System.out.print("Easy as pie");
System.out.print("Easy as pie");
System.out.println("Easy as pie");
System.out.println("");
System.out.print("I am a place holder, the line below can be highlighted!");
System.out.println();
System.out.println("This line below the placeholder was once blank, now it's not!");
System.out.println(" ");
System.out.print("Easy as pie");
System.out.println(" I want PIE!!!");
System.out.print("ThePie is all GONE?");
}
}
Output:
Easy as pie
Easy as pieEasy as pieEasy as pie
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
I want
PIE!!!
ThePie
is all
GONE?
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.