Java题库——chapter7 多维数组
1)Which of the following statements are correct? 1) _______
A)char[ ][ ] charArray = {{'a', 'b'}, {'c', 'd'}};
B)char[2][2] charArray = {{'a', 'b'}, {'c', 'd'}};
C)char[2][ ] charArray = {{'a', 'b'}, {'c', 'd'}};
D)char[ ][ ] charArray = {'a', 'b'};
二维数组静态初始化[ ][ ]不允许出现数字
2)Assume double[ ][ ] x = new double[4][5], what are x.length and x[2].length? 2) _______
A)5 and 5 B) 4 and 4 C) 5 and 4 D) 4 and 5
x.length返回该二维数组中一维数组元素的个数
x[2].length返回一维数组中元素的个数。
3)Analyze the following code:
public class Test { public static void main(String[ ] args) { boolean[ ][ ] x = new boolean[3][ ]; x[0] = new boolean[1];
x[1] = new boolean[2]; x[2] = new boolean[3]; System.out.println("x[2][2] is " + x[2][2]); } }
A)The program has a runtime error because x[2][2] is null.
B)The program has a compile error because new boolean[3][ ] is wrong.
C)The program runs and displays x[2][2] is null.
D)The program runs and displays x[2][2] is true.
E)The program runs and displays x[2][2] is false.
4)Suppose a method p has the following heading:
public static int[ ][ ] p()
What return statement may be used in p()?
A)return 1;
B)return int[ ]{1, 2, 3};
C)return {1, 2, 3};
D)return new int[ ][ ]{{1, 2, 3}, {2, 4, 5}};
E)return new int[ ]{1, 2, 3};
5)Assume double[ ][ ][ ] x = new double[4][5][6], what are x.length, x[2].length, and x[0][0].length? 5) _______
A)4, 5, and 4 B) 4, 5, and 6 C)6, 5, and 4 D) 5, 5, and 5
6)Which of the following statements are correct? (Choose all that apply.) 6) _______
A)char[ ][ ][ ] charArray = new char[2][2][ ];
B)char[ ][ ][ ] charArray = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}};
C)char[2][2][ ] charArray = {'a', 'b'};
D)char[ ][ ][ ] charArray = {{'a', 'b'}, {'c', 'd'}, {'e', 'f'}};