gpt4 book ai didi

java - input.nextLine 的类型安全?

转载 作者:塔克拉玛干 更新时间:2023-11-02 07:48:17 30 4
gpt4 key购买 nike

如果使用 Scanner< 将 input.nextLine() 的值分配给 String 变量,是否会引发异常?/

就像你把

String foo = input.nextInt();

您会得到一个 InputMismatchException。所以我想知道是否有任何可能的方法可以从以下方面获得异常(exception):

String foo = input.nextLine();

这可能是个愚蠢的问题,但我需要绝对确定。

提前致谢!

最佳答案

docs 中的答案:

Throws:
NoSuchElementException - if no line was found
IllegalStateException - if this scanner is closed

让生活更轻松、更安全的提示:始终引用文档。

关于java - input.nextLine 的类型安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20331645/

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