logo Practice-It logo

arrayMystery

Language/Type: Java arrays array mystery
Author: Marty Stepp (on 2010/12/28)

Consider the following method:

public static void arrayMystery(int[] a) {
    for (int i = a.length - 1; i >= 1; i--) {
        if (a[i] > a[i - 1] + 10) { 
            a[i - 1] = a[i - 1] + 5;
        }
    }
}

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, 99}; arrayMystery(a1);
int[] a2 = {6, 18, 4, 25}; arrayMystery(a2);
int[] a3 = {5, 10, 20, 35, 40}; arrayMystery(a3);
int[] a4 = {-20, 20, 26, 32, 50, 3}; arrayMystery(a4);
int[] a5 = {5, 10, 16, 21, 27, 40, 55}; arrayMystery(a5);

You must log in before you can solve this problem.


Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.