1、二维数组的运用
二位数组的运用
注意:对与二维数组来说每一行所包含的列数相当于一个新的一维数组。
2、在一个二维数组中存放三名学生的语文和数学成绩,并求语文和数学的总成绩和平均分。
二位数组的运用
二位数组的运用
代码如下:import java.util.Scanner;

public class venture {
public static void main(String[] args) {
int[][]score=new int[3][2];
int yuwen=0;int shuxue=0;
Scanner sc=new Scanner(System.in);
for(int i=0;i<score.length;i++){
for(int j=0;j<score[i].length;j++){
if(j==0){
System.out.println(“输入第”+(i+1)+“个学生的语文成绩:”);
score [i][j]=sc.nextInt();
yuwen+=score[i][j];
}
else
{System.out.println(“输入第”+(i+1)+“个学生的数学成绩:”);
score[i][j]=sc.nextInt();
shuxue+=score[i][j];
}
}
}
System.out.println(“语文总成绩为:”+yuwen);
System.out.println(“语文平均分为:”+yuwen/score.length);
System.out.println(“数学总成绩为:”+shuxue);
System.out.println(“数学平均分为:”+shuxue/score.length);
}
}

相关文章:

  • 2022-12-23
  • 2021-06-29
  • 2022-12-23
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2022-03-05
猜你喜欢
  • 2021-07-15
  • 2021-10-19
  • 2022-12-23
  • 2021-06-14
  • 2021-11-10
  • 2021-06-13
  • 2021-07-10
相关资源
相似解决方案