?

AP® Computer Science A

Free Version

Upgrade subject to access all content

Moderate

Fastest Scenario for Method with String Array Parameter

APCSA-6FNPLX

Consider the following method.

public int finder(String[] array, String s)
{
     for(int i=array.length-1; i>=0; i--)
     {
         if (array[i].equals(s))
             return i;
     }
     return -1;
}

Which of the following calls to this method would run the fastest (require the least number of passes through the loop)?

A
String[] a = {"cat", "tiger","zebra"};
int foundPos = finder(a, "zebra");
B
String[] a = {"cat", "dog","frog","tiger","zebra"};
int foundPos = finder(a, "dog");
C
String[] a = {"cat", "dog","frog","tiger","zebra"};
int foundPos = finder(a, "frog");
D
String[] a = {"cat", "dog","frog","tiger"};
int foundPos = finder(a, "frog");
E
String[] a = {"cat", "dog","frog","tiger","zebra"};
int foundPos = finder(a, "cat");