logo CodeStepByStep logo

mystery2

Language/Type: Java arrays

Consider the following method:

public static void arrayMystery2(int[] a) {
    for (int i = 1; i < a.length - 1; i++) {
        a[i] = a[i - 1] - a[i] + a[i + 1];
    }
}

Indicate in the right-hand column what values would be stored in the array after the method arrayMystery executes if each integer array below is passed as a parameter to it.

int[] a1 = {42, 42}; arrayMystery2(a1);
int[] a2 = {6, 2, 4}; arrayMystery2(a2);
int[] a3 = {7, 7, 3, 8, 2}; arrayMystery2(a3);
int[] a4 = {4, 2, 3, 1, 2, 5}; arrayMystery2(a4);
int[] a5 = {6, 0, -1, 3, 5, 0, -3}; arrayMystery2(a5);

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.