写一个计算平均温度的方法。

huangapple go评论75阅读模式
英文:

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&lt;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];

huangapple
  • 本文由 发表于 2020年8月11日 04:56:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/63347924.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定