0
我需要幫助解決我的輸出代碼問題。對不起,我需要幫助修復輸出的大塊代碼。這兩個輸入文件可以找到(即將張貼)操作順序
請問你是否需要什麼輸出看起來像或公式解決hI(我只能發佈兩個鏈接。)。
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class HeatIndex
{
public static void main(String[] args) throws IOException
{
String location = "Key West, Florida";
File fileNameTemp = new File("KeyWestTemp.txt");
File fileNameHumid = new File("KeyWestHumid.txt");
Scanner inFileTemp = new Scanner(fileNameTemp);
Scanner inFileHumid = new Scanner(fileNameHumid);
String [] month = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "Novermber", "December"};
int length = month.length;
double [] temperature = new double[length];
int [] humidity = new int[length];
double [] hI = new double[length];
//INPUT - read in data for temp and humidity from files
int n = 0; //index value for arrays
while(inFileTemp.hasNextDouble())
{
temperature[n] = inFileTemp.nextDouble();
//System.out.println (temperature[n]); //debug statement - uncomment to see values assignned to temperature
n++;
}
inFileTemp.close();
n = 0; //reset index to 0
while (inFileHumid.hasNextDouble())
{
humidity[n] = inFileHumid.nextInt();
//System.out.println (humidity[n]); //debug statement - uncomment to see values assignned to humidity
n++;
}
inFileHumid.close();
//PROCESSING - calculate Heat Index if needed- see lecture notes for details, formula is incomplete
double t = 0.0;
int h = 0;
for(n = 0; n < hI.length; n++)
{
if(temperature[n] >= 80.0 ) //determine if HI should be calculated, complete the condition based on Lecture notes
{
t = temperature[n];
h = humidity[n];
hI[n] = -42.379 + 2.04901523*t+ 10.1433312*h- 0.22475541*t*h- 0.000683783*(t*t)- 0.005481717* (h*h)+ 0.000122874*(h*h)*t+ 0.000085282*t*(h*h)- 0.000000199*(t*t)*(h*h);
}
代碼有什麼問題?它應該做什麼,它究竟做了什麼? – dg99
代碼的問題是它正常出來,但是當溫度進入80以上時,代碼就會嚇倒並開始輸出負數,我認爲這是操作順序的問題。 – FlyingKalamari
「hI」在哪裏定義?我在你的代碼示例中沒有看到它。 – dg99