?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Difficult

Sequential Search Using While Loop and an Array of Ints

APCSA-YZD16U

The following method performs a sequential search and returns the position of the first occurrence of key if it is found in array arr, or it returns -1 if it is not found:

public static int sequentialSearch(int[] arr, int key)
{
    int i = 0;
    while ( /*missing code*/ )
        i++;

    if (i == arr.length)
        return -1;
    else
        return i;
}

Which of the following should replace

/*missing code*/?
A
i < arr.length
B
arr[i] == key
C
arr[i] == key && i < arr.length
D
arr[i] != key && i < arr.length
E
arr[i] != key || i < arr.length