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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!