273,745 views
43 votes
43 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 Junejo
by
2.8k points

1 Answer

24 votes
24 votes

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 Morteza Baghalpoor
by
3.1k points