繁体   English   中英

Method(double, double) 不适用于参数 (double[], double[])

[英]Method(double, double) is not applicable for the arguments (double[], double[])

import java.io.*;
import java.util.*;
public class HeatIndex
{
    public static double [] loadKeyWestTemp() throws IOException//method to    read temp text file and convert to an array
{
    Scanner inFile = new Scanner(new File("KeyWestTemp.txt"));
    List<Double> array = new ArrayList<>();
    while(inFile.hasNext()){
        array.add(inFile.nextDouble());
    }
    double t[] = new double[array.size()];
    for(int i = 0; i < array.size(); i++){
        t[i] = array.get(i);
    }
    inFile.close();
    return t;
}

public static double [] loadKeyWestHumidity () throws IOException//method to read humidity text file and convert to array
{
    Scanner inFile = new Scanner(new File("KeyWestHumid.txt"));//finding text file
    List<Double> array = new ArrayList<>();//initializing Array List
    while(inFile.hasNext()){//while-loop to fill array list
        array.add(inFile.nextDouble());
    }
    double h[] = new double[array.size()];//assigning array list values to the h[] array
    for(int z = 0; z < array.size(); z++){
        h[z] = array.get(z);
    }
    inFile.close();//closing inFile
    return h;//returning h[]
}
public static double heatIndex(double t, double h){//method to calculate the Heat Index formula{
    //declaring variables that are a part of the Heat Index formula
    double H1 = -42.379;
    double H2 = 2.04901523;
    double H3 = 10.14333127;
    double H4 = 0.22475541;
    double H5 = 6.83783 * .001;
    double H6 = -5.481717 * .01;
    double H7 = 1.22874 * .001;
    double H8 = 8.5282 * .0001;
    double H9 = 1.99 * 000001;
    //the actual formula
    double index = (H1) + (H2*t) + (H3 * h) + (H4 * t * h) + (H5 * (t * t)) + (H6 * (h * h)) + (H7 *(t * t)*h) + (H8 * t *(h * h)) + (H9 * (t * t)*(h * h));
    return index;
}
public static void main(String[]args)throws IOException {//main method
    for(int y = 0; y < 11; y++){
        double HI [] = heatIndex(loadKeyWestTemp(),loadKeyWestHumidity());
        }
    }
}

我正在编写一个程序,从两个文本文件中读取温度和湿度百分比,然后使用其中的值从这些值中找到热指数。 我在行中收到错误: double HI [] = heatIndex(loadKeyWestTemp(),loadKeyWestHumidity()); 它说我不允许使用包含 double[] 的双精度的 a 方法。 有没有一种方法可以解决这个问题,而不必重写我的程序的主要部分? 谢谢!

您需要索引双数组中的元素:

double kwt = loadKeyWestTemp();
double kph = loadKeyWestHumidity();
double HI = new double[kwt.length];

for(int y = 0; y < 11; y++){
    HI[y] = heatIndex(kit[y], kph[y]);
}

这是假设这两种方法返回相同大小的数组 (11)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM