小编Xen*_*nce的帖子

如何在扫描仪输入之前运行一段时间?

我正在尝试编写一个循环,直到我在运行应用程序的控制台中键入特定文本.就像是:

while (true) {
try {
    System.out.println("Waiting for input...");
    Thread.currentThread();
    Thread.sleep(2000);
    if (input_is_equal_to_STOP){ // if user type STOP in terminal
        break;
    }
} catch (InterruptedException ie) {
    // If this thread was intrrupted by nother thread
}}
Run Code Online (Sandbox Code Playgroud)

而且我希望它在每次通过时写一行,所以我不希望它在一段时间内停止并等待下一个输入.我需要使用多个线程吗?

java java.util.scanner

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

java ×1

java.util.scanner ×1