Solved

Which Code Snippet Calculates the Sum of All the Even

Question 62

Multiple Choice

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


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

Correct Answer:

verifed

Verified

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

Related Questions