Unit 1 Lesson 1 Homework

Part A: Core Understanding

  1. Identify the job of a Java compiler.



  1. Determine the error family in each situation.
    a. The compiler rejects a statement because its semicolon is missing.
    b. The program starts, but crashes while it is running.
    c. The program runs successfully, but prints the wrong result.



  1. Identify which comment form is best for each purpose from //, /* ... */, and /** ... */.
    a. A short note beside one statement
    b. A comment that continues across several lines



Part B: Read and Trace

  1. Determine the exact output.
System.out.print("Ready ");
System.out.println("to code");
System.out.print("Go!");



  1. Determine the exact output.
System.out.println("Line 1\nLine 2");
System.out.println("She said \"Java!\"");



  1. Determine the value of each expression.
    a. 18 - 3 * 4
    b. (18 - 3) * 4
    c. 23 / 5
    d. 23 % 5



Part C: Find and Fix

  1. Correct the statement so it prints She said "Hello".
System.out.println("She said "Hello"");




  1. Correct the syntax error without changing the printed message.
System.out.println("Welcome to Java")




Part D: Write Code

  1. Write Java output statements that produce the following result. A complete main method is not required.
Menu
"Pizza" costs $8
C:\food





  1. Explain why the expression 9 / 4 produces 2 instead of 2.25 in this lesson's Java code.