9.8.1. Easier Multiple Choice QuestionsΒΆ
These problems are easier than most of those that you will usually see on the AP CSA exam.
- 2
- The size of outer array is the number of rows. Remember that two-dimensional arrays are actually an array of arrays in Java.
- 4
- The size of the inner array is the number of columns.
- 8
- This is the total number of items in the array.
8-8-1: How many columns does a
have if it is created as follows int[][] a = { {2, 4, 6, 8}, {1, 2, 3, 4}};
?
You can see how the array looks by clicking on the following Ex-9-7-1.
strGrid[0][2] = "S";
- The code
letterGrid[0][2] = "S";
actually sets the 1st row and 3rd column to hold a reference to theString
object "S". strGrid[1][3] = "S";
- This would be true if row and column indices started at 1 instead of 0 and if this was in column major order.
strGrid[3][1] = "S";
- This would be true if row and column indices started at 1 instead of 0.
strGrid[2][0] = "S";
- In row-major order the row is specified first followed by the column. Row and column indices start with 0. So
letterGrid[2][0]
is the 3rd row and 1st column. strGrid[0][0] = "S";
- This would set the element at the first row and column.
8-8-2: Which of the following statements assigns the letter S to the third row and first column of a two-dimensional array named strGrid
(assuming row-major order).
- a[0][3]
- This would be true if the row index started at 0, but the column index started at 1.
- a[1][3]
- Both the row and column indices start with 0.
- a[0][2]
- The value 6 is at row 0 and column 2.
- a[2][0]
- The row index is specified first, then the column index.
- a[3][1]
- The row index is specified first and the indices start at 0.
8-8-3: How would you get the value 6 out of the following array int[][] a = { {2, 4, 6, 8}, {1, 2, 3, 4}};
?
You have attempted of activities on this page