logo Practice-It logo

arrayMystery

Language/Type: Java arrays array mystery
Author: Roy McElmurry

Consider the following method:

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

Indicate what values would be stored in the array after the method arrayMystery executes if the integer array in the left-hand column is passed as a parameter to it.

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