まず第一に、受け入れられた入力に対して何もしていません。次の入力を無視するだけです。
次に、scanner.nextLine()
読み取った次の行である文字列を返します。string
トークンを個別に取得するには、読み取りを分割して取得する必要があります。
3 番目に、次の入力があるかどうかを while でチェックする必要がscanner#hasNextLine
ありtrue
ます。
各トークンを個別に読み取りたい場合Scanner#next
は、次に読み取ったトークンを返すメソッドを使用することをお勧めします。
integers
また、とを読みたいstrings
ので、整数を持っているかどうかもテストする必要があります。Scanner#hasNextInt
そのためにはメソッドを使用する必要があります。
各行integer
で個別に読みたいので、わかりました。string
あなたが試すことができるものは次のとおりです: -
while (scanner.hasNextLine()) { // Check whether you have nextLine to read
String str = scanner.nextLine(); // Read the nextLine
if (str.equals("stop")) { // If line is "stop" break
break;
}
String[] tokens = str.split(" ", 1); // Split your string with limit 1
// This will give you 2 length array
int firstValue = Integer.parseInt(tokens[0]); // Get 1st integer value
String secondString = tokens[1]; // Get next string after integer value
}