我已经对此进行了多次测试,但是我不知道出了什么问题。
每次我编译时,它都会按预期的那样要求范围,但是在设置upperRange之后,它会继续要求更多输入,而从未进入程序的其余部分。
这是最重要的部分:
Scanner in = new Scanner(System.in);
System.out.printf("%30s%n","Range of Years");
System.out.println("Enter the lowest year of the range:");
int lowerRange = in.nextInt();
System.out.println("Enter the highest year of the range:");
int upperRange = in.nextInt();
if(lowerRange>upperRange){
System.out.println("Please make sure the upper range is later than the lower range.");
System.out.println("Enter the lowest year of the range:");
lowerRange = in.nextInt();
System.out.println("Enter the highest year of the range:");
upperRange = in.nextInt();
}
else if(lowerRange<1995){
System.out.println("Sorry, no data on hurricanes from before 1995. Please try 1995 or later.");
System.out.println("Enter the lowest year of the range:");
lowerRange = in.nextInt();
System.out.println("Enter the highest year of the range:");
upperRange = in.nextInt();
}
else if(upperRange>2015){
System.out.println("Sorry, no data on hurricanes from after 2015. Please try 2015 or earlier.");
System.out.println("Enter the highest year of the range:");
upperRange = in.nextInt();
}
String token = "";
File hurricaneData = new File("hurricanedata.txt");
Scanner inFile = new Scanner(hurricaneData);
int counter = 0;
while(inFile.hasNextLine()){
counter++;
inFile.hasNextLine();
}