Worksheets2D Arrays
Total questions: 12
Worksheet time: 7mins
What will result from this?
{{2,0,2},{0,2,0}}
{{2,0,2},{2,0,2}}
{{0,0,0},{0,0,0}}
Out of Bounds Index Error
How would you print the top right value in an array
arr[arr.length-1][0]
arr[arr.length-1][arr[0].length-1]
arr[0][arr[0].length-1]
arr[0][0]
The first [] in a 2D array is for the column
True
False
What value will this print out
4
1
0
7
How do you properly change a value in a 2D array?
arr[oldValue] = newValue
arr[x][y] = value
You can't
boolean[][] x = new boolean[3][5]
What is the value of x.length?
2
3
4
5
Which one prints all the elements greater than 20 in order?
for(int r = 0;r < array.length;r++){
for(int c=0; c<array[r].length;c++){
if (array[r][c] > 20){
System.out.println(array[r][c]);
for(intr=0;r<array.length;r++){
for(int c=0; c<array.length;c++){
if (array[r][c] > 20){
System.out.println(array[r][c]);
for(int c = 0;c < array[0].length;c++){
for(int r = 0; r < array.length;r++){
if (array[r][c] > 20){
System.out.println(array[r][c]);
What is the array after the code is executed?
2 1 0
2 1 0
2 1 0
1 2 3
1 2 3
1 2 3
0 1 2
0 1 2
0 1 2
0 1 2
3 4 5
6 7 8
What is sum after the code is finished?
42
9
10
4
{ {2 3 3}, {1 2 3},
{1 1 2}, {1 1 1} }
{ {2 1 1}, {3 2 1},
{3 3 2}, {3 3 3} }
{ {2 1 1 1}, {3 2 1 1}, {3 3 2 1} }
Out of Bounds error
Which of the following would set the third element in the fifth row to "S".
array[5,3] = "S";
array[3][5] = "S";
array[5][3] = "S";
array[3,5] = "S";
How would you print the last element of each array?(Assume all arrays are the same length)
for(int c = 0 ; c < arr[0].length;c++){ print(array[c][arr.length];
for(int c = 0 ; c < arr[0].length;c++){ print(array[c][arr.length-1];
for(int c = 0 ; c <= arr[0].length;c++){ print(array[c][arr.length-1];
for(int c = 1 ; c <= arr[0].length;c++){ print(array[c][arr.length-1];
