java多维数组题目_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 classTest {public static voidmain(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‘}};

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值