Haz*_* C. 0 java arrays multidimensional-array indexoutofboundsexception
我正试图从我的2d String数组中获取默认的空值.
到目前为止我已经有了这个.
String[][] sterren = new String[12][37];
int h = 12;
String leeg = "";
while(h > 0){
int b = 37;
sterren[h][b] = leeg;
while(b > 0){
sterren[h][b] = leeg;
b = b-1;
}
h = h-1;
}
Run Code Online (Sandbox Code Playgroud)
h =高度,b =宽度
当我尝试执行此操作时,我在行上获得了一个arrayindexoutofbounds 12 sterren[h][b] = leeg;.为什么这是因为我清楚地制作了12列和37行.
new String[12][37]表示length每个数组的12和37,它们分别可以容纳12个和37个对象.因为数组从索引开始,0这意味着它们只有索引0- length - 1.这意味着如果数组的长度为12,则它具有索引0- 11.在此示例中,您尝试12在外部数组中添加index 并将索引添加37到内部数组(其最后一个索引所在的数组36).
为了使这项工作有h = 11和b = 36并制作while循环while h >=0和while b >= 0.
| 归档时间: |
|
| 查看次数: |
55 次 |
| 最近记录: |