所以我在调试这段代码时遇到了麻烦,想寻求你的帮助..
所以这是代码: import 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。我希望你能帮助我,我的项目需要这个。
谢谢!