此类运行但是当我在扫描仪中输入内容时没有任何反应。它应该注册输入并运行另一个类,然后我得到响应并尝试打印它。
public class Eliza {
public static void main(String[] args) {
String line = "";
String response = "";
ElizaResponder responder = new ElizaResponder();
System.out.println("Welcome to Christian Rebelo's Eliza");
System.out.println("---------------------------");
System.out.println("ELIZA> " + responder.getGreeting());
Scanner s = new Scanner(System.in);
while (responder.isNotFinished()) {
line = s.nextLine();
}
response = responder.getResponse(line);
System.out.println(response);
System.out.println("ELIZA> " + responder.getFarewell());
}
}
答案 0 :(得分:1)
根据评论来判断:
while (responder.isNotFinished()) {
line = s.nextLine();
}
response = responder.getResponse(line);
System.out.println(response);
应该是这样的:
while (responder.isNotFinished()) {
line = s.nextLine();
response = responder.getResponse(line);
System.out.println(response);
}
答案 1 :(得分:0)
此:
while (responder.isNotFinished()) {
line = s.nextLine();
}
根本不会读取任何行,或者在没有输入任何内容的情况下读取无数行。