Question: What does the following algorithm do? public static void mystery(int[] nums) { for (int i = 0; i < nums.length; i++) { if (nums[i] %
What does the following algorithm do?
public static void mystery(int[] nums)
{ for (int i = 0; i < nums.length; i++)
{
if (nums[i] % 2 == 0)
{
nums[i]++; }
}
}
-
Add one to every other value in the array.
Add one to every other value in the array.
-
Doubles all the values in the array.
Doubles all the values in the array.
-
Adds 1 to every value in the array.
Adds 1 to every value in the array.
-
Changes all elements in the array to odd.
Changes all elements in the array to odd.
-
Tests if the elements in the array are even or odd.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
