打卡~请老师检查有没出错~

来源:1-8 编程练习

Heijyu

2020-05-13 23:56:49

package imooc.comArray;

import java.util.Scanner;

public class ExerciseIntArray {

	public static void main(String[] args) {
		   //定义一个三行两列的整型二维数组intArray
	       int[][] intArray = new int [3][2];
	       //从键盘输入学生成绩,要求输入顺序与效果图一致
	       Scanner sc = new Scanner(System.in);
	       int sumChi = 0;
	       int sumMath = 0;
	       for(int i=0; i<intArray.length; i++){
	           for(int j=0; j<intArray[i].length; j++){
	               if(j==0){
	                   System.out.println("Please enter Chinese score:");
	                   sumChi = sumChi + sc.nextInt();
	               }
	               else{
	                   System.out.println("Please enter Math score");
	                   sumMath = sumMath + sc.nextInt();
	               }
	           }
	           
	       }
	       //求语文的总成绩和平均分
	       int avgChi = sumChi/intArray.length;
	       System.out.println("The total score of Chinese is:" + sumChi);
	       System.out.println("The average score of Chinese is:" + avgChi);
	       //求数学的总成绩和平均分
	       int avgMath = sumMath/intArray.length;
	       System.out.println("The total score of Math is:" + sumMath);
	       System.out.println("The average score of Math is:" + avgMath);

	}

}


写回答

1回答

好帮手慕阿园

2020-05-14

 同学的代码运行没有问题,但是同学没有把添加的数据存入数组中

 建议将数据存储在二维数组中,可以参考如下代码:

http://img.mukewang.com/climg/5ebcf8e10989150c06670296.jpg

这样三名学生的成绩存储到二维数组中了

很棒,继续加油!

如果我的回答解决了你的疑惑,请采纳,祝学习愉快~


0

0 学习 · 16556 问题

查看课程