logo CodeStepByStep logo

arrayMysteryExam5

Language/Type: Java arrays array mystery

Consider the following method:

public static void arrayMystery(int[] a) {
    for (int i = 0; i < a.length - 1; i++) {
        if (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 executes if each integer array below is passed as a parameter to it.

int[] a1 = {2, 4}; arrayMystery(a1);
int[] a2 = {1, 3, 6}; arrayMystery(a2);
int[] a3 = {7, 2, 8, 4}; arrayMystery(a3);
int[] a4 = {5, 2, 7, 2, 4}; arrayMystery(a4);
int[] a5 = {2, 4, 6, 3, 7, 9}; arrayMystery(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.