Consider the following instance variable and method. private int[] arr; public void mystery() { for (int k = arr.length - 1; k >= 0; k--) { arr[k] = arr[k % 2]; } } Which of the following best describes what the method mystery does to the array arr when it is called?

Respuesta :

Answer:

Even indexes of arr receive the value stored at the position 0 of the array.

Odd indexes of arr receive the value stored at the position 1 of the array.

Explanation:

The options are not there, but we can answer.

Basically, even indexes of the array receive the value stored at the position 0 of the array. Odd indexes of the array receive the index at the position 1 of the array.

k%2 = 0 if k is even

k%2 = 1 if k is odd

Otras preguntas

ACCESS MORE
EDU ACCESS