应该把分数都定义成double变量更加合理,毕竟分数会有小数的情况存在
public class demo1 { public static void main(String[] args) { int clanum=4; int stunum=3; for(int c=1;c<=clanum;c++){ double sum=0; System.out.println("***输入第"+c+"个班级的学生分数***"); for(int s=1;s<=stunum;s++){ System.out.print("输入第"+s+"个的学生分数:"); double score=new Scanner(System.in).nextDouble(); sum=sum+score; } double avg=sum/stunum; System.out.println("平均分:"+avg); } } }