【发布时间】:2013-08-21 21:38:07
【问题描述】:
我有一个像这样的对象数组:
1:[沃尔沃,200],[捷豹,900]
2:[宝马,300]
3:[斯柯达,100], [(无输入)] , [(无输入)]
这是我只打印具有值的区域的方法(内部有一些格式,但这不是问题)。得到一个超出范围的错误......我需要做什么?谢谢!
public static void printMat(Car[][] carMat){
int row = 0;
int column = 0;
while ((carMat[row][column] != null)){
System.out.printf("( %-8s : %,9d )", carMat[row][column].getName(), carMat[row][column].getPrice());
if (column == carMat[row].length - 1){
System.out.print("\n");
row++;
column = 0;
} else {
column++;
}
}
}
【问题讨论】:
标签: java arrays methods indexing bounds