Extracting a Column from a 2D Array
Consider the following client code and method:
int[][] grid = {{5,5,5},{10,10,10},{15,15,15}};
int[] arr = mystery(grid, 2);
for (int num : arr)
System.out.print(num + " ");
public static int[] mystery(int[][] arr, int n)
{
int[] m = new int[arr.length];
for (int i = 0; i < arr.length; i++)
m[i] = arr[i][n];
return m;
}
What will be printed after the code executes?
A
10 10 10
B
5 10 15
C
5 10 10
D
15 15 15
Question Leaderboard
Not enough data yet to show leaderboard.
APFIVE