当前位置: 动力学知识库 > 问答 > 编程问答 >

Having a beginner issue with some basic math functions in Java. Anything I'm doing wrong?

问题描述:

EDIT: Thanks a ton for everyone who has helped. I can't believe I missed that single typo.

I'm in need of help for some basic math in Java. I'm trying to create a heat index calculator but when Java compiles runs the program the calculator seems to slip up. I've checked it over multiple times to see the problem but cant find anything. Help would be greatly appreciated.

Code:

 double t = 84.3; //temperature

int h = 81; //humidity

//the following are parts of the heat index formula

double c1 = -42.379;

double c2 = 2.04901523;

double c3 = 10.14333127;

double c4 = -0.22475541;

double c5 = -.00683783;

double c6 = -5.481717E-2;

double c7 = 1.22874E-3;

double c8 = 8.5282E-4;

double c9 = -1.99E-6;

double hI = c1 + c2 * t + c3 * h + c4 * t * h + c5 * t*t + c6 * h*h + c7 * t*t * h + c8 * t + h*h + c9 * t*t * h*h; //formula for calculating heat index

System.out.println(hI);

So the problem here is that instead of giving me the desired output (heat index), it's returning a very large number (6184.5981258548). Is there an issue with my code? Once again, any help would be appreciated. Thanks.

网友答案:

According to the Heat Index Wikipedia page, then c8 term should be:

c8TR2

But you have for that term:

c8 * t + h*h 

Try

c8 * t * h*h 

Making this change, I get as output:

95.21440841480018
网友答案:

You have a typo in c8*t + h*h It should be c8*t*h*h

分享给朋友:
您可能感兴趣的文章:
随机阅读: