Skip to main content

AP CSA MCQ Practice

Full-Length APCSA MCQ Practice Test 2

Full-Length APCSA MCQ Practice Test 2 - Practice Mode

Question 1 of 42

Answered 0 of 42

Choose one answer.

Assume a is non-null. Which precondition prevents firstIndex from throwing an exception?

public class ArraySearchContext
{
    public static int firstIndex(int[] a, int t)
    {
        int i = 0;
        while (a[i] != t)
        {
            i++;
        }
        return i;
    }

    public static void main(String[] args)
    {
        int[] sampleA = {1, 3, 5, 7};
        int sampleT = 3;
        int result = firstIndex(sampleA, sampleT);
        System.out.print(result);
    }
}
Choose one answer.