【发布时间】:2013-09-11 11:48:56
【问题描述】:
所以我在调试这段代码时遇到了麻烦,想寻求你的帮助..
所以这是代码: 导入 java.io.*;
公共类 PrefEx2{ public static void main(String args[]) throws IOException{
int quiz, ave, sum=0;
BufferedReader inpt = new BufferedReader (new InputStreamReader(System.in));
// System.out.print("Section 1");
for (int sect=1; sect<4; sect++){
System.out.print("Section " + sect);
for (int x=1; x<4; x++){
System.out.println("\n Student " + x);
for (int y=1; y<4; y++){
System.out.print("Quiz " + y + ": ");
quiz=Integer.parseInt(inpt.readLine());
sum=sum+quiz;
}
ave=sum/3;
System.out.print("Average: " + ave);
System.out.println("");
}
}
System.out.println("");
}
}
我想在输出中显示的内容:
第 1 节(最多 3 节)
-学生1
-- 测验1:xx
-- 测验2:xx
-- 测验3:xx
-- 平均:xx
-学生2
-- 测验1:xx
-- 测验2:xx
-- 测验3:xx
-- 平均:xx
-学生3
-- 测验1:xx
-- 测验2:xx
-- 测验3:xx
-- 平均:xx
=============================
所以这段代码中的问题是平均总结本身 就像例如 学生 1 的平均成绩为 94 然后下一个平均数是 186 而不是 92.. 我希望你能帮助我,我的项目需要这个。
谢谢!
【问题讨论】:
-
哦!谢谢大家,我现在修好了:)