logo Practice-It logo

arrayMystery3

Language/Type: Java array mystery arrays
Author: Marty Stepp

Consider the following method:

public static void mystery(int[] data) {
    for (int i = 1; i < data.length - 1; i++) {
        if (data[i] == data[i - 1] + data[i + 1]) {
            data[i] = data[i] / 2;
        }
    }
}

For each array below, indicate what the array's contents would be after the method mystery were called and passed that array as its parameter.

{3, 7, 4}
{0, 3, 7, 4, 1}
{4, 3, 8, 5, 1, 2}
{2, 1, 5, 4, 10, 6, 2}
{1, 2, 1, 2, 1, 2, 1}

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.