logoDiscussion 2 handout

Group members (names & NetIDs)

Objectives

Problem 1: Object diagrams

Draw labeled boxes for variables “x”, “y”, “a”, and “b”. Then execute the following assignment statements by hand, adding and erasing values and arrows in your diagram accordingly.

    x = 3;
    y = 2 * x;
    x = 7;
    z = y;

    a = "world";
    b = a;
    a = "hello";
object diagram template

Problem 2: Multidimensional arrays

Draw an object diagram to illustrate execution of the following statements:

int[][] a = new int[3][];
a[0] = new int[]{3, 1, 4};
a[1] = new int[]{1, 5};
a[2] = a[0];
a[2][1] = 2;

Recall the semantics of the assignment statement from last week’s discussion. Based on that, what should happen when the following statement is executed?

a[1][2] = 9;

Problem 3: Program arguments

Implement an “echo” program that prints each argument passed to it, separated by spaces. Starter code is provided on the “dis02” project archive on the course website.

Example:

$ java Echo My name   is  Hal.
My name is Hal.
public class Echo {
    public static void main(String[] args) {






    }
}