Problem of the Day
Monday, March 2, 2026
Problem:
The int array vals stores a series of values. Which of the following code segments will reverse the order of that array of values?
for (int i = 0; i < vals.length / 2; i++)
{
int j = vals.length - i - 1;
int tmp = vals[i];
vals[i] = vals[j];
vals[j] = tmp;
}int[] vals2 = new int[vals.length];
int j = 0;
for (int i = vals.length - 1; i >= 0; i--)
{
vals2[j] = vals[i];
j++;
}
vals = vals2;int j = vals.length - 1;
for (int i = 0; i < vals.length / 2; i++)
{
int tmp = vals[i];
vals[i] = vals[j];
vals[j] = tmp;
j--;
}
- I only
- II only
- I and II only
- I and III only
- I, II, and III
The correct answer is e. All three solutions will result in a reversal of the values in the array vals.