练习题错的地方
int改为double对吗?
int改为double对吗?
2018-08-13
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); } } }
举报