Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我编写了一个 for 循环,它从标准输入读取每一行并返回第一个非空白字符,但我不知道如何指示我的 Scanner 是否已超出我正在阅读的行尾?请指教!
如果您正在阅读每一行,为什么您需要担心扫描仪何时脱线?读取一行后,将该行保存在String变量中并遍历字符串。用来String.length()确定长度,这样你就不会跑到最后。
String
String.length()