![](/img/trans.png)
[英]how to solve The method add(double, double, int, double) in the type main is not applicable for the arguments (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.