这是我从文件中读取并在控制台中显示的代码
try
{
BufferedReader readFile = new BufferedReader(new FileReader("sales.txt"));
String line = "";
while((line = readFile.readLine()) != null)
{
String tmp[] = line.split(",");
year = Integer.parseInt(tmp[0]);
quarter = tmp[1];
sales = Integer.parseInt(tmp[2]);
//System.out.printf("Year: %s\tQuarter: %s\tSales: %d\n",year,quarter,sales);
}
readFile.close();
}
catch(IOException e)
{
e.printStackTrace();
}
userInput.close();
在我名为“sales.txt”的文件中,我有这个:
2012年第一季度9300
2012,Q2,10225
2012年第三季度12420
2012年第四季度13250
2013年第一季度10500
2013,Q2,10900
2013年第三季度11340
2013年第四季度14600
现在我被困在如何计算 2012 年和 2013 年第四季度的平均销售额