我没有得到什么错误,如果有人向我解释它以便我(或你)可以解决它将会很有帮助。
我的许多程序一直出现的错误是:
文件:F:\ Java Work \ Classexample3.java [line:40]
错误:解析时到达文件末尾
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Classexample3 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String answer;
System.out.println("What kind of beverage do you want? (hot or cold)");
answer = br.readline();
if (answer.equals("hot")) {
System.out.println("Please choose an item from the list below:");
System.out.println("- tea \n- coffee");
answer = br.readline();
if (answer.equals("tea")) {
System.out.println("You have purchased a hot tea:");
} else if (answer.equals("coffee")) {
System.out.println("You have purchased a hot coffee");
answer = br.readline();
}
} else if (answer.equals("cold")) {
System.out.println("Please choose an item from the list below:");
System.out.println("- bubble tea \n- pop");
answer = br.readline();
if (answer.equal("bubble tea")) {
System.out.println("You have purchased a cold bubble tea");
} else if (answer.equals("pop")) {
System.out.println("You have purchased a cold pop");
} else {
System.out.println("This item is not on the list");
}
}
}
答案 0 :(得分:0)
你最后错过}
来关闭课程。
答案 1 :(得分:0)
您错过了}
来关闭相应的public class Classexample3 {
。错误与它所声明的完全相同 - Java编译器期望在某些时候关闭类声明,但文件结束时没有这样做。
答案 2 :(得分:0)
该错误意味着某些东西没有像关闭括号一样被关闭。您的Classexample3
类的结束括号似乎在代码底部缺失。
答案 3 :(得分:0)
关闭课程后,如果您缺少}
,则会出现很多其他错误。
首先,br.readline()
应为br.readLine()
其次,answer.equal("bubble tea")
应为answer.equals("bubble tea")
这些事情很重要,如果您使用IDE,它将使您作为Java开发人员的生活变得更加轻松:)