gpt4 book ai didi

java - sc.hasNextInt() 什么时候等待输入?

转载 作者:行者123 更新时间:2023-11-30 10:45:10 24 4
gpt4 key购买 nike

<分区>

根据 util.Scanner.hasNextInt() 的 Java 文档:

Returns true if there is another line in the input of this scanner. This method may block while waiting for input. The scanner does not advance past any input.

当使用hasNextInt()时,可能会导致扫描器等待用户的输入。

例如:

System.out.println("Enter something:");
while(!scn.hasNextInt()){
//do whatever..
}

输出:

Enter something:_     //(The underscore indicates the prompt waiting for user input)

我的问题是:hasNextInt() 什么时候会等待输入,什么时候不会?是不是当输入/输出缓冲区中没有 token 可接收时,它会等待输入?

注意:我不是在问如何使用 .hasNextInt() 实现正确的代码。我在问什么时候 hasNextInt() 会等待输入。

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