Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

  1. To 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 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 "".

  6. 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 
  7. Using only println(), output:

    I want PIE!!!! 
  8. Using exactly 5 print() methods, output:

    ThePie is all GONE?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

=+1 Why are local employment laws important to IHRM?

Answered: 1 week ago

Question

=+ Are some laws more important than others? If so, which ones?

Answered: 1 week ago