我有一個任務,我必須在1980年到2006年的文件中閱讀有關颶風的信息。我無法弄清楚錯誤是什麼。我有一段代碼是這樣的:java.util.InputMismatchException; null(在java.util.Scanner中)
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
public class Hurricanes2
{
public static void main(String[] args)throws IOException
{
//declare and initialize variables
int arrayLength = 59;
int [] year = new int[arrayLength];
String [] month = new String[arrayLength];
File fileName = new File("hurcdata2.txt");
Scanner inFile = new Scanner(fileName);
//INPUT - read data in from the file
int index = 0;
while (inFile.hasNext()) {
year[index] = inFile.nextInt();
month[index] = inFile.next();
}
inFile.close();
這只是第一部分。但在while語句部分,year[index] = inFile.nextInt()
有錯誤。我不知道錯誤意味着什麼,我需要幫助。提前致謝。
我想這和它沒有改變錯誤。感謝您盡力幫助。 –