Question 1 of 10
A ferry ticket bar stores lane numbers in a 1D array and linear-searches from index 0. Each comparison tests equality with the target. What text does this Java code display?
int[] lanes = {4, 7, 1, 9};
int target = 7;
int checks = 0;
int found = -1;
for (int i = 0; i < lanes.length; i++) {
checks++;
if (lanes[i] == target) {
found = i;
break;
}
}
System.out.print(found + " " + checks);
- A. 1 2
- B. 1 4
- C. 0 1
- D. -1 4