快捷导航

使用.split()报错数组越界怎么处理?

publicstaticvoidshowTotalScoreAvg()throwsIOException{doublesum=0;BufferedReaderin=newBufferedReader(newFileReader(path));StringstudentScore;while((studentScore=in.readLine())!=null){doublemathScore=Double.parseDouble(studentScore.split("\t")[2]);doubleenglishScore=Double.parseDouble(studentScore.split("\t")[3]);doublecomputerScore=Double.parseDouble(studentScore.split("\t")[4]);doubletotalScore=mathScore+englishScore+computerScore;sum=sum+totalScore;count++;if(MinTotalScore>totalScore){MinTotalScore=totalScore;}if(MaxTotalScore

免责声明:本内容仅代表回答者见解不代表本站观点,请谨慎对待。

版权声明:作者保留权利,不代表本站立场。

回复

使用道具 举报

参与会员2

在写出这种取具体数组下标语句前,我有个建议,先判断下数组长度。

目前该问题描述的代码是因为该字符串不符合程序预期的长度[文件中体现的分数没有超过2个 /t]
回复

使用道具 举报

已解决
回复

使用道具 举报

可能感兴趣的问答

发新帖
TA的信息
  • 会员所属: 注册会员
  • 认证信息: 邮箱认证手机认证
  • 微信访问
  • 手机APP