Solved

Which Code Snippet Calculates the Sum of All the Elements

Question 2

Multiple Choice

Which code snippet calculates the sum of all the elements in even positions in an array?


A) int sum = 0;
For (int i = 1; i < values.length; i+=2)
{
Sum++;
}
B) int sum = 0;
For (int i = 0; i < values.length; i++)
{
Sum++;
}
C) int sum = 0;
For (int i = 0; i < values.length; i++)
{
Sum += values[i];
}
D) int sum = 0;
For (int i = 0; i < values.length; i + 2)
{
Sum += values[i];
}

Correct Answer:

verifed

Verified

Related Questions