Which of the following are true? (Choose two.)
20: int[] v [] = new int[10][20]; 21: for (int i = 0; i < v.length; i++) 22: for (int j = 0; j < v.length; j++) 23: v[i][j] = 'x'; 24: System.out.println(v.size());
A, E.
Line 24 does not compile because arrays use length.
It is ArrayList that uses size()
.
All of the other lines compile, making Option A correct.
It is allowed to split up the braces in the 2D array declaration on line 20.
The code is also allowed to use v.length as the loop condition on line 22.
The array starts out with all 200 of the cells initialized to the default value for an int of 0.
Both loops iterate starting at 0 and stopping before 10, which causes only half of the array to be set to 'x'.
The other half still has the initial default value of 0, making Option E correct.