Ask Question

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]++;

}

}

1. Adds 1 to every value in the array.

2. Tests if the elements in the array are even or odd.

3. Changes all the values in the array to even numbers.

4. Doubles all the values in the array.

5. Doubles every other value in the array.

+4
Answers (2)
  1. 2 January, 11:53
    0
    2. Tests if the elements in the array are even or odd.
  2. 2 January, 12:01
    0
    The purpose of the program code is to change each value into an even number. If the number is even already, it does not change the number. If the number is odd, it will add one and change it to an even number.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “What does the following algorithm do? public static void mystery (int nums[]) { for (int i = 0; i < nums. length; i++) { if (nums[i] % 2! = ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers