Solved

Which Code Snippet Calculates the Sum of All the Elements

Question 77

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 = i + 2)
{
Sum += values[i];
}

Correct Answer:

verifed

Verified

Unlock this answer now
Get Access to more Verified Answers free of charge

Related Questions