logo CodeStepByStep logo

array2dMystery2

Language/Type: Java arrays multi-dimensional arrays

Consider the following method. For each multi-dimensional array listed below, write the final array state that would result if the given array were passed as a parameter to the method.

public void array2dMystery2(int[][] a) {
    for (int r = 0; r < a.length; r++) {
        for (int c = a[0].length - 2; c > 0; c--) {
            a[r][c] = a[r][c - 1] + a[r][c + 1];
        }
    }
}
int[][] a1 = {{2, 1, 6}, {5, 8, 9}, {1, -5, -4}};
int[][] a2 = {{1, 2, 3, 4, 5}, {2, 4, 6, 8, 10}, {0, 1, 2, 3, 4}};

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.