Chapter 8 Multidimensional Arrays
Section 8.2 Two–Dimensional Array Basics
Section 8.2.1 Declaring Variables of Two–Dimensional Arrays and Creating Two–Dimensional Arrays
1. Which of the following statements are correct?
a. char[][] charArray = {‘a’, ‘b’};
b. char[2][2] charArray = {{‘a’, ‘b’}, {‘c’, ‘d’}};
c. char[2][] charArray = {{‘a’, ‘b’}, {‘c’, ‘d’}};
d. char[][] charArray = {{‘a‘, ‘b’}, {‘c’, ‘d’}};
#
3. What is the index variable for the element at the first row and first column in array a?
a. a[0][0]
b. a[1][1]
c. a[0][1]
d. a[1][0]
#
4. When you create an array using the following statement, the element values are automatically initialized to 0.
int[][] matrix = new int[5][5];
a. True
b. False
#
Section 8.2.2 Obtaining the Lengths of Two–Dimensional Arrays
2. Assume double[][] x = new double[4][5], what are x.length and x[2].length?
a. 4 and 4
b. 4 and 5
c. 5 and 4
d. 5 and 5
#
5. How many elements are in array matrix (int[][] matrix = new int[5][5])?
a. 14
b. 20
c. 25
d. 30
#
7. Assume int[][] x = {{1, 2}, {3, 4}, {5, 6}}, what are x.length are x[0].length?
a. 2 and 1
b. 2 and 2
c. 3 and 2
d. 2 and 3
e. 3 and 3