我无法在2D数组中获取最后一列来打印

时间:2017-01-31 06:35:25

标签: java arrays

我的任务是获取原始的2D数组,并计算每个索引的权重并使用新值创建一个新数组。我只是无法输出新数组的最后一列

谢谢!

1 个答案:

答案 0 :(得分:2)

你的循环应如下所示:

for (int i = 0; i < calcWeight.length; i++) {
     // note the calcWeight[i], you´ll get the first dimension length
     // if you leave out the [i] part
     // This way your inner loop would stop at 4 (rather 5 because <=) 
     // instead of its actuall length, 6
     for (int j = 0; j < calcWeight[i].length; j++) {
        ...
     }
}