public static void showTotalScoreAvg() throws IOException{
double sum = 0;
BufferedReader in = new BufferedReader(new FileReader(path));
String studentScore;
while((studentScore = in.readLine()) != null)
{
double mathScore = Double.parseDouble(studentScore.split("\t")[2]);
double englishScore = Double.parseDouble(studentScore.split("\t")[3]);
double computerScore = Double.parseDouble(studentScore.split("\t")[4]);
double totalScore = mathScore + englishScore +computerScore;
sum = sum + totalScore;
count++;
if(MinTotalScore > totalScore)
{
MinTotalScore = totalScore;
}
if(MaxTotalScore < totalScore)
{
MaxTotalScore = totalScore;
}
studentScore = in.readLine();
}
double totalScoreAvg = sum/(double)count;
System.out.println("总成绩平均分为:"+ totalScoreAvg);in.close();
}
3 回答
小草1434
TA贡献106条经验 获得超23个赞
在写出这种取具体数组下标语句前,我有个建议,先判断下数组长度。
目前该问题描述的代码是因为该字符串不符合程序预期的长度[文件中体现的分数没有超过2个 /t]
添加回答
举报
0/150
提交
取消