Learn AP Comp Sci

Problem of the Day

Wednesday, February 18, 2026


Problem:

An array of int values has been created as shown.

int[] values = {32, 17, 11, 19, 20, 41};

Now consider the following static method.

public static void mystery(int[] arr)
{
for (int i = 0; i < arr.length; i++)
{
if (i % 2 == 0)
arr[i] = arr[i] / 2;
else
arr[i] = arr[i] + 1;
}
}

Which set of values represents the state of the array after the call mystery(values)?

  1. {32, 17, 11, 19, 20, 41}
  2. {32, 17, 11, 19, 20, 41}
  3. {16, 18, 5, 20, 10, 42}
  4. {16, 18, 5.5, 20, 10, 42}

Show solution:

The correct answer is c. For items at even-numbered locations in the list (where i % 2 == 0), the value there is divided as an integer (producing an integer result). For items at odd-indexed locations, 1 is added to the value there.