所以我已经将代码编写到一个程序中,该程序应该初始化来自不同位置的总计数据集并显示它们。出于某种原因,我在第一个 for 循环中不断收到运行时错误,无法弄清楚原因。有人可以帮我弄清楚我做错了什么吗?
public class Sales {
private static String[] months;
private static String[] cities;
private static int[] citySum;
private static int[] monthlySum;
private static int[][] sales;
private static int col;
private static int row;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
calCityTotal();
calMonthlyTotal();
displayTable();
}
public Sales() {
months = new String[] {"January","Febuary","March","April",
"May","June"};
cities = new String[] {"Chilliwack","Kamloops","Kelowna",
"NanaimoSurrey","Vancouver","Victoria"};
sales = new int[][] {{400,500,500,600,500,600},
{600,800,800,800,900,900},
{700,700,700,900,900,1000},
{500,600,700,800,700,700},
{900,900,900,1000,1100,1100}};
citySum = new int[sales.length];
monthlySum = new int[sales[0].length];
}
public static void calCityTotal() {
for (row = 0; row < sales.length; row++){
for (col = 0; col < sales[0].length; col++){
citySum[col] += sales[row][col];
}
}
}
public static void calMonthlyTotal() {
for (row = 0; row < sales.length; row++){
for (col = 0; col < sales[0].length; col++){
monthlySum[row] += sales[row][col];
}
}
}
侃侃无极
翻过高山走不出你
相关分类