简体   繁体   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());
        }
    }
}

I am writing a program that reads the temperatures and humidity percentages from two text files and then uses the values inside to find the Heat Index from those values.我正在编写一个程序,从两个文本文件中读取温度和湿度百分比,然后使用其中的值从这些值中找到热指数。 I am getting an error in the line: double HI [] = heatIndex(loadKeyWestTemp(),loadKeyWestHumidity());我在行中收到错误: double HI [] = heatIndex(loadKeyWestTemp(),loadKeyWestHumidity()); It says that I am not allowed to use the a method that contains doubles with double[].它说我不允许使用包含 double[] 的双精度的 a 方法。 Is there a way I can fix this without having to rewrite major parts of my program?有没有一种方法可以解决这个问题,而不必重写我的程序的主要部分? Thank you!谢谢!

You need to index the elements in the double array:您需要索引双数组中的元素:

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]);
}

This is assuming the two methods return arrays the same size (11).这是假设这两种方法返回相同大小的数组 (11)。

暂无
暂无

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

相关问题 如何解决 main 类型中的方法 add(double, double, int, double) 不适用于参数 (double, double, double, double) - how to solve The method add(double, double, int, double) in the type main is not applicable for the arguments (double, double, double, double) double类型的方法parsedouble字符串不适用于double参数 - the method parsedouble string in the type double is not applicable for the arguments double PrintStream 类型中的方法 println(double) 不适用于 arguments (String, double) - The method println(double) in the type PrintStream is not applicable for the arguments (String, double) main类型的方法(double [])不适用于参数(int []) - The method (double[]) in the type main is not applicable for the arguments (int[]) PathIterator类型的currentSegment(float [])方法不适用于参数(Double []) - The method currentSegment(float[]) in the type PathIterator is not applicable for the arguments (Double[]) WebElement类型的方法sendKeys(CharSequence…)不适用于参数(双精度) - The method sendKeys(CharSequence…) in the type WebElement is not applicable for the arguments (double) Java:printf不适用于参数(字符串,双精度) - Java: printf is not applicable for the arguments (String, double) 不带参数并返回双精度的方法 - method that takes no arguments and returns double Java Writer 错误:Writer 类型中的方法 write(char[], int, int) 不适用于 arguments (int, double, int, String) - Java Writer error: The method write(char[], int, int) in the type Writer is not applicable for the arguments (int, double, int, String) Car Anylogic 类型未定义方法 getDistanceByRoute(double, double, double, double) - The method getDistanceByRoute(double, double, double, double) is undefined for the type Car Anylogic
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM