For practice use only.
Full-Length APCSA MCQ Practice Test 2 - Timed Mode
Full-Length APCSA MCQ Practice Test 2 with a 90-minute timer for AP Computer Science A MCQ pacing practice.
Time left 90:00
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);
}
}