CSC1110 Homework 1

Consider the following sequence of commands:

1   int a = 5, b = 2;
2   double c = 3.0;
4   a += b;
5   b++;
6   c--;
7   c *= a;
8   System.out.println("a + b + c = " + (a + b + c));

a. Trace this sequence, filling in the table below. Write only the changes in memory or output on the line where the changes occur.


b. Use the provided template to write a Java program that executes these commands on the computer. Since the class name is Homework1, the text file where the program is saved should be called

 * Course: CSC1110
 * Assignment: Homework 1

 * Enter the code for Homework 1 in the main method of this
 * class. Once it is entered, compile the code down to
 * bytecode, then execute the program in the terminal.
 * Take a screenshot of the compilation and execution
 * and submit that screenshot, along with the completed
 * program trace.
public class Homework1 {
    public static void main(String[] args) {
        // TODO: Enter the code here

c. Compile your program in the terminal and execute the bytecode to compare the trace you performed on the first page with the program output. If they are not the same, double check both the entered code and your trace.

To compile your program:

Use the javac program to compile your .java file to a bytecode .class file. The command will look like this:


This will create a bytecode file called Homework1.class in the same directory as

To execute your program:

Now use the java program to run the Java Virtual Machine, which will interpret your bytecode and execute the program. The java command only wants the name of the class that contains your main method, so your command will look like this:

java Homework1

Submission Instructions:

Submit a PDF document with your completed table and screenshots of both your Java code and a terminal window showing the output of the program after it has executed.