Solved

Which Code Snippet Calculates the Sum of All the Even

Question 29

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

Unlock this Answer For Free Now!

View this answer and more for free by performing one of the following actions

qr-code

Scan the QR code to install the App and get 2 free unlocks

upload documents

Unlock quizzes for free by uploading documents