int改为double对吗?
为啥我改了double还是不对
是的,double可以兼容int,但反过来就错了
public class HelloWorld { public static void main(String[] args) { int classNum = 3; int stuNum = 4; double sum = 0; double avg = 0; Scanner input = new Scanner(System.in); for(int i = 0;i < classNum;i++) { System.out.println("请输入第"+(i+1)+"个班级的分数信息!"); sum = 0; for(int j = 0;j < stuNum;j++) { System.out.print("请输入第"+(j+1)+"个学生的分数信息:"); // 如果改成double,则就要用到nextDouble; double score = input.nextDouble(); sum += score; } avg = sum/stuNum; System.out.println("请输入第"+(i+1)+"个班级的平均分:"+ avg); } } }