logo Practice-It logo

arrayMystery

Language/Type: Java arrays array mystery
Author: Whitaker Brand

Consider the following method:

public static int arrayMystery(int[] array) {
    int x = 0;
    for (int i = 0; i < array.length - 1; i++) {
        if (array[i] > array[i + 1]) {
            x++;
        }
    }
    return x;
}

Indicate in the right-hand column what value would be returned after the method arrayMystery executes if each integer array below is passed as a parameter to it.

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