英文:
Write a method for calculate average temp
问题
我正在尝试编写一个返回平均温度的方法。但是我收到了以下错误消息:
org.opentest4j.AssertionFailedError: 期望值:<23.0>,但实际值为:<0.0>。
有什么问题?
public class TempBewerking {
public static double calculateTempAverage(double[] temp)
{
temp = new double[7];
double tempAverage = 0;
for (int a = 0; a < temp.length; a++)
tempAverage += temp[a];
tempAverage = tempAverage / temp.length;
return tempAverage;
}
}
英文:
I'm trying to write a method that returns the average temperature.
But I get the following error message:
org.opentest4j.AssertionFailedError: expected: <23.0> but was: <0.0>
What's wrong?
public class TempBewerking {
public static double calculateTempAverage(double [] temp)
{
temp = new double [7];
double tempAverage =0;
for (int a = 0; a<temp.length;a++)
tempAverage+=temp[a];
tempAverage=tempAverage/temp.length;
return tempAverage;
}
}
答案1
得分: 1
"It's normal cause you are reassigning the temp Array. temp = new double [7];"
英文:
it's normal cause you are reassigning the temp Array. temp = new double [7];
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论