Skip to main content

Unit 4 · Data Collections

Array Search

Array Search MCQ Practice

Question 1 of 15

Answered 0 of 15

Choose one answer.

What is printed by the following code segment?

public class ArraySearchContext
{
    public static void runExample()
    {
        int[] a = {4, 7, 2};
        int found = -1;
        for (int i = 0; i < a.length; i++)
        {
            if (a[i] == 7)
            {
                found = i;
            }
        }
        System.out.print(found);
    }

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