Skip to main content

Unit 4 · Data Collections

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?

public class LinearAndBinarySearchContext
{
    public static void runExample()
    {
        int[] a = {2, 5, 9, 14};
        int lo = 0;
        int hi = a.length - 1;
        int mid = (lo + hi) / 2;
        System.out.print(mid + " " + a[mid]);
    }

    public static void main(String[] args)
    {
        runExample();
    }
}
Choose one answer.