logo CodeStepByStep logo

array2dMystery

Language/Type: Java arrays array mystery

Consider the following method:

public void arrayMystery2D(int[][] numbers) {
    for (int r = 0; r < numbers.length; r++) {
        for (int c = 0; c < numbers[0].length - 1; c++) {
            if (numbers[r][c + 1] > numbers[r][c]) {
                numbers[r][c] = numbers[r][c + 1];
            }
        }
    }
}

If a two-dimensional array numbers is initialized to the following values, what are its contents after the call of arrayMystery2D(numbers); ?

int[][] numbers = {
    {3, 4, 5, 6},
    {4, 5, 6, 7},
    {5, 6, 7, 8}
};
arrayMystery2D(numbers);
row 0
row 1
row 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.