For Loop Array Traversal
Consider the following method.
public static int mystery(int[] arr)
{
int x = 0;
for (int k = 0; k < arr.length; k = k + 2)
x = x + arr[k];
return x;
}
Assume that the array nums is declared and initialized as follows.
int[] nums = {3, 6, 1, 0, 1, 4, 2};
What value is returned by the call mystery(nums)?
A
7
B
17
C
10
D
5
Question Leaderboard
Not enough data yet to show leaderboard.
