运营顺序

时间:2013-11-23 00:00:40

标签: java

我需要帮助解决输出代码问题。抱歉,我需要帮助修复hI的输出。可以找到两个输入文件(即将发布)

请询问您是否需要输出的内容或解决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);
}

1 个答案:

答案 0 :(得分:0)

根本不是编码问题,这是公式的问题。您需要在scientific notation上学习。

0.000683783应为0.00683783(6.83783x10 -3

0.005481717应为0.05481717(-5.481717x10 -2

请参阅formula