142k views
1 vote
After the following code executes what are the values in array2? (2 points):

int[] array1 (6, 3, 9, 1, 11);
int[] array2 = (0, 0, 0, 0, 0);
int a2 = 0;
for (int al = 0; al < array1.length - 1; a1++)
(
}
if (array1[al] >= 5)
(
}
array2 [a2] = array1[al];
a2++;
(A) (0, 0, 0, 0, 0);
(B) (6, 9, 0, 0, 0);
(C) (6, 0, 9, 0, 11);
(D) {6, 9, 11, 0, 0);
(E) (6, 3, 9, 1, 11); by

1 Answer

2 votes

Answer:

After this code executes, the values in array2 would be (6, 9, 0, 0, 0) because the code loops through array1 and checks if each element is greater than or equal to 5. If it is, the element is added to array2 and a2 is incremented. In this case, array1 has two elements that are greater than or equal to 5, which are 6 and 9. So array2 will have those values in the first two elements, and the remaining elements will be 0. Therefore, the answer is (B) (6, 9, 0, 0, 0)

User Tifu
by
7.8k points