【发布时间】:2022-01-04 03:29:58
【问题描述】:
char[][] isbns = {
{'9', '6', '0', '-', '4', '2', '5', '-', '0', '5', '9', '-', '0'},
{'8', '0', '-', '9', '0', '2', '7', '4', '4', '-', '1', '-', '6'},
{'0', '-', '8', '0', '4', '4', '-', '2', '9', '5', '8', '-', 'X'},
{'0', '-', '9', '4', '3', '3', '9', '6', '-', '0', '4', '-', '2'},
{'0', '-', '9', '7', '5', '2', '2', '9', '8', '-', '0', '-', '5'},
{'9', '9', '7', '1', '-', '5', '-', '0', '2', 'l', '0', '-', '0'},
{'9', '3', '-', '8', '6', '5', '4', '-', '-', '2', '1', '-', '4'},
{'9', '9', '9', '2', '1', '-', '5', '8', '8', '-', '1', '0', '7'}
};
上面的数组是这样的,我的方法如下
public static Object[] getColumn(char[][] arr, int index){
Object[] column = new Object[arr[0].length];
for(int i = 0; i < column.length; i++){
column[i] = arr[i][index];
}
return column;
}
但是,由于行是 8,列是 13 个字符,我得到数组索引超出范围异常错误。
我该如何解决这个问题?谢谢。
【问题讨论】:
-
发帖前总是搜索 Stack Overflow。