イムとして数を決定するものではありません。連続した2つの数字を入力すると(スペースで区切られています)、最初の数字は長いと認識されますが、2番目の数字は認識されません。スキャナは、私が見つけたこのコードで実験しようとしている
import java.util.*;
public class ScannerDemo {
public static void main(String[] args) {
String s = "Hello World! 35 62 + 3.0 = 6.0 true ";
Long l = 13964599874l;
s = s + l;
// create a new scanner with the specified String Object
Scanner scanner = new Scanner(s);
// find the next long token and print it
// loop for the whole scanner
while (scanner.hasNext()) {
// if no long is found, print "Not Found:" and the token
System.out.println("Not Found: " + scanner.next());
// if the next is a long, print found and the long
if (scanner.hasNextLong()) {
System.out.println("Found: " + scanner.nextLong());
}
}
// close the scanner
scanner.close();
}
}
結果:なぜ62は
Not Found :Hello
Not Found :World!
Found :35
Not Found :62
Not Found :+
Not Found :3.0
Not Found :=
Not Found :6.0
Not Found :true
Found :13964599874
を見つけていませんか?あなたのコードで
あなたが起こるか見てステップにより、デバッグやステップを使用しようとしたことがありますか? * 62 *はscanner.hasNext()によって読み取られ、次のステートメントは* Not Found *と表示されます。 – Alex