【发布时间】:2021-10-27 00:13:28
【问题描述】:
我有一个 txt 文件,里面有几行这样的
7. SSWAB 38 15 - 57
但我不需要所有的值,只需要字符串和整数。
我会使用 nextInt 作为整数,但我该如何处理 1. 和 -?
还有字符串,什么是有用的nextString? next够了吗?
我尝试过这样的事情,只是使用令牌,但没有任何反应
scanner.next(); //7.
String s = (scanner.next()); //SAVES sswab
Integer n1 = scanner.nextInt(); //38
Integer n2 = scanner.nextInt(); //15
Integer n3 = scanner.nextInt(); //- is skipped, as next int is 57
【问题讨论】: