logo CodeStepByStep logo

arrayIntListMystery1

Suppose the following method is added to the ArrayIntList class:

public void mystery() {
    int n = 0;
    for (int i = 0; i < size; i++) {
        n += elementData[i] * i;
    }
    elementData[size] = n;
    size++;
}

What is the output of the following client code?

ArrayIntList list = new ArrayIntList();
list.add(14);
list.add(3);
list.add(6);
list.add(2);
list.mystery();
System.out.println("list = " + list);
System.out.println("size = " + list.size());
line 1
line 2

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.