Method Analysis With Nested Loops
Consider the findSomething method below. Assume that arrays a and b have the same length.
public static boolean findSomething(int[] a, int[] b) {
for (int aValue: a) {
boolean found = false;
for (int bValue: b) {
if (bValue == aValue)
found = true;
}
if (!found)
return false;
}
return true;
}
The findSomething method returns true if and only if which of the following is true?
A
array a contains at least one element that is also in b.
B
arrays a and b contain identical elements in the same order.
C
arrays a and b contain identical elements in reverse order.
D
every element of array a is also in b.
Question Leaderboard
Not enough data yet to show leaderboard.
