所以,我一直在为我的计算机科学课程编写一些代码来计算热量指数。我无法将我被指示使用的文本文件中的数据加载到程序将使用的数组中。您看到注释掉的块是我正在尝试的另一种解决方案,它也不起作用......我应该如何修复它?谢谢!
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class HeatIndex
{
public static void main(String [] args) throws IOException
{
Scanner keyWestHumidScan = new Scanner(new File("KeyWestHumid.txt"));
Scanner keyWestTempScan = new Scanner(new File("KeyWestTemp.txt"));
int counter1 = 0;
int counter2 = 0;
int [] keyWestHumid = {};
double [] keyWestTemp = {};
String header1 = " Heat index: Key West, Florida ";
String header2 = "\n Months \n ";
String [] months = {"Jan ", "Feb ", "Mar ", "Apr ", "May ", "Jun ", "Jul ", "Aug ", "Sep ", "Oct ", "Nov ", "Dec ", "Avg \n"};
String header3 = "*************************************************************************************";
String [] Labels = {"Temp (F) \n", "Hudimitiy (%) \n", "HI (F) "};
//read keyWestHumid into array
while(keyWestHumidScan.hasNext())
{
keyWestHumid[counter1] = keyWestHumidScan.nextInt();
counter1++;
//String data1_parse = keyWestHumidScan.next();
///int data1 = Integer.parseInt(data1_parse);
//keyWestHumid[counter1] = data1;
//counter1++;
}
//read keyWestTemp into array
while(keyWestTempScan.hasNext())
{
String data2_parse = keyWestTempScan.next();
double data2 = Double.parseDouble(data2_parse);
keyWestTemp[counter2] = data2;
counter2++;
}
System.out.println(header1);
System.out.print(header2);
for(String headData:months) {
System.out.print(headData);
}
System.out.println(header3);
for(String headData:Labels) {
System.out.print(headData);
}
}
}