132k views
5 votes
Consider the following incomplete method that is intended to return an array that contains the contents of its first array parameter follow by contents of its second array parameter.

public static int[] appen(int[] al, int[] a2)
{
int[] result = new int[al.length + a2.length]
for (int j = 0; j < al.length; j++)
result[j] = al[j];
for (int k = 0; k < a2.length; k++)
result[ / index / ] = a2[k]
return result;
}
Which of the following expressions can be used to replace / index / so that append will work as intended?
(A) j
(B) k
(C) k + al.length - 1
(D) k + al.length
(E) k + al.length + 1

User Smitelli
by
3.9k points

1 Answer

1 vote

Answer: (D) k + a1.length

Step-by-step explanation:

The best way to learn these type of questions would be to create a main class, where you implement the appen() method and test all of the options A-E

User Asya
by
3.5k points