Skip to main content

Java Topic Practice

Accumulators and Counters

Accumulators and Counters MCQ Practice

Question 1 of 15

Answered 0 of 15

Choose one answer.

What is printed by the following code segment?

int[] data = {4, 9, 2, 7, 5, 1};
int sum = 0;
int count = 0;
for (int v : data) {
  if (v > 2) {
    sum += v;
    count++;
  }
}
System.out.print(sum + ":" + count);
Choose one answer.