帮我看下这个小程序!在线等

nbe01 2009-12-12 09:37:14

import java.io.*;
public class Example4_1
{
public static void main(String args[]) throws IOException
{
int score[]=new int[3];
int i = 0;
for( i=0;i<3;i++);
{
System.out.print("请输入一个学生的成绩");
try
{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
String s=in.readLine();

score[i]=Integer.parseInt(s);

}catch(IOException e)
{

}
}
int sum=0;
for( i=0;i<3;i++)
{
sum+=score[i];

}
System.out.println("平均成绩为"+sum/3);
}

}



怎么实现不了啊???
这是提示:
请输入一个学生的成绩10 10 10
Exception in thread "main" java.lang.NumberFormatException: For input string: "10 10 10"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at Example4_1.main(Example4_1.java:16)
...全文
88 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyahui0124505 2009-12-12
  • 打赏
  • 举报
回复
数字应该一个一个输入!
nbe01 2009-12-12
  • 打赏
  • 举报
回复
看到了 谢谢了啊
swandragon 2009-12-12
  • 打赏
  • 举报
回复

public static void main(String[] args){
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int score[] = new int[3];
for(int i = 0;i < 3;i++){
System.out.print("请输入一个学生的成绩");
try{
String s = in.readLine();
score[i] = Integer.parseInt(s);
}catch(IOException e){

}
}
int sum = 0;
for(int i = 0;i < 3;i++){
sum += score[i];

}
System.out.println("平均成绩为" + sum / 3);

}
swandragon 2009-12-12
  • 打赏
  • 举报
回复
for(int i=0;i<3;i++);

后面多了个;

62,621

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧