?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Easy

Sequential Search Algorithm Tracing

APCSA-LEKLWY

Consider the following method.

public static int seqSearch(int[] x, int key)
{
    for (int i = 0; i < x.length; i++)
    {
        if (key == x[i])
            return i;
    }
    return -1;
}

Which of the following statements is TRUE?

A

the for loop always iterates x.length times

B

the method never returns -1

C

the last return statement is unreachable

D

key and x[i] cannot be compared using the == operator

E

0 is returned only if key was found in the first comparison