Conditional Summation of Even Numbers
Consider the following RecordProcessor class.
public class RecordProcessor {
private int[] records;
public RecordProcessor(int[] initialRecords) {
records = initialRecords;
}
public void calculateSum() {
int sum = 0;
for (int val : records) {
if (/* condition missing */) {
sum += val;
}
}
System.out.println("Sum: " + sum);
}
}
Which of the following boolean expressions, when substituted for /* condition missing */, will cause the calculateSum method to compute the sum of only the even numbers in the records array?
A
val != records[0]
B
val <= 0
C
val % 2 == 0
D
val > 5
Question Leaderboard
Not enough data yet to show leaderboard.
