Skip to main content

Java Topic Practice

Array Basics

Array Basics 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 pivot = data[1];
int result = 0;
for (int i = 0; i < data.length; i++) {
  if (i % 2 == 0) {
    result += data[i] - pivot;
  } else if (data[i] >= pivot) {
    result += data[i] % 2;
  } else {
    result -= i;
  }
}
System.out.print(result);
Choose one answer.