public void calculatePercentage(int exam[][])
{
int perc = 0;
for (int i = 0; i < examen.length; i++)
{
for (int[] score : exam)
perc += score;
perc /= exam.length;
}
}
你好,我真的被困在这个了。给定参数exam [] [],我想创建一个新的mathod calculatePercentages。双数组考试包含 3 行元素。该方法所要做的就是简单地计算每一行的总和。答案可能很简单,但我只是不知道该怎么做。对于单个数组,我猜代码是:
double perc = 0;
for(int score : exam)
{
perc += score;
}
perc /= (exam.length);
return perc;
考试[][] 可能看起来像:
|10 12 18 5 3 | |12 3 5 15 20 | |20 15 13 11 9 |
输出百分比 [] 应该像:
{48,55,68} percent[] 的每个元素是exam[] 1 行元素的总和