gpt4 book ai didi

java - 扫描仪不会接受输入,因此无法处理它

转载 作者:行者123 更新时间:2023-12-01 13:12:04 25 4
gpt4 key购买 nike

该类运行,但当我在扫描仪中输入内容时,什么也没有发生。它应该注册输入并运行另一个类,然后我在其中获取响应并尝试打印它。

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());
}
}

最佳答案

从评论来看,它看起来像这样:

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);
}

关于java - 扫描仪不会接受输入,因此无法处理它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22774005/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com