1
所以,這裏是問題:我試圖讓我的代碼簡單。我從一行中有多個數據項的文件中讀取數據,因此我想將它們拆分並放入相應的數組中。但是,IDE不斷告訴我它找不到符號。我已經嘗試導入字符串類(正確的單詞?)並將我的元素數組移到WHILE循環中。我究竟做錯了什麼?萬聖節快樂! :)找不到符號 - 拆分方法(Java)
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.lang.String;
public class Hurricanes2
{
public static void main(String [] args) throws IOException
{
int counter = 0;
String [] token = new String[64];
String [] hurrcaneYear = new String[64];
String [] hurrcaneName = new String[64];
int [] hurricaneCategory = new int[64];
double [] hurrcanePressure = new double[64];
double tempKnots;
double knotsToMph;
double [] hurricaneWindSpeeds = new double[64];
double categoryAverage;
double pressureAverage;
double speedAverage;
String headerData = " Hurricanes 1980 - 2006\n\n Year Hurricane Category Pressure(MB) Wind Speed (MPH)\n========================================================================";
Scanner in = new Scanner(System.in);
Scanner inFile = new Scanner(new File("hurcData2.txt"));
System.out.print(headerData);
/**---Use for-each (line:token)
* Parse for year - > year array
* parse for name - > name array
* parse for knots - > tempKnots
* knotsToMph = tempKnots * 1.15078
* hurricaneWindSpeed[counter] = knotsToMph
* enter if-else to calculate category (hurricaneCategory [] = 1,2,3,4, or 5):
* 74-95 cat1
* 96-110 cat2
* 111 - 129 cat3
* 130-156 cat4
* 157 or higher cat 5
*
*
*/
while(inFile.hasNext())
{
token[counter] = in.nextLine();
String tokenElements[] = token.split(" ");
counter++;
}
for(String line:token)
{
}
}
}