Skip to main content

Java Topic Practice

Linear and Binary Search

Linear and Binary Search 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 target = 7;
int index = -1;
for (int i = 0; i < data.length; i++) {
  if (data[i] == target && index == -1) index = i;
}
System.out.print(index);
Choose one answer.