Activity 12.5.1.
What would the following code return from mystery([90, -30, 50], 50)?
public static int mystery(int[] elements, int target)
{
for (int j = 0; j < elements.length; j++)
{
if (elements[j] == target)
{
return j;
}
}
return -1;
}
- -1
- This value is returned if the target is not in the list since this is a sequential search.
- 0
- This would be true if the target was 90 since this is a sequential search.
- 1
- This would be true if the target was -30 since this is a sequential search.
- 2
- This is a sequential search that returns the index where the target appears in the elements list
- 50
- A sequential search returns the index, not the value. What is the index of the 50?

