Skip to main content

AP CSA MCQ Practice

Full-Length APCSA MCQ Practice Test 2

Practice mode lets students check each answer immediately and read the explanation before moving on.

For practice use only.

Full-Length APCSA MCQ Practice Test 2 - Practice Mode

Full-Length APCSA MCQ Practice Test 2 in practice mode with per-question answer checks and explanations.

Question 1 of 42

Answered 0 of 42

Choose one answer.

Identify the weakest condition that guarantees all accesses are valid, the method terminates, and its contract can be met. Account explicitly for unbounded search loop, preconditions, and array bounds. Which precondition prevents firstIndex from throwing?

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.