如何解析(通过循环)一个字符串直到字符串结束?
How to parse (via loop) through a string until the end of the string?
Given String "5 6 7 8 9 2 3 " how do you use a while loop or for loop to cycle through each number without repeating the string (as a while loop would)?
String myString = "5 6 7 8 9 2 3";
Scanner myScanner = new Scanner(myString);
while(myScanner.hasNext())
{
//do something
}
I can't get the loop the stop. It keeps repeating the same string pattern over and over and over.
到目前为止,您的代码询问扫描仪是否有更多项目。但你从不消费它们。所以在你的循环中你需要调用类似
的东西
String currentItem = myScanner.next();
Given String "5 6 7 8 9 2 3 " how do you use a while loop or for loop to cycle through each number without repeating the string (as a while loop would)?
String myString = "5 6 7 8 9 2 3";
Scanner myScanner = new Scanner(myString);
while(myScanner.hasNext())
{
//do something
}
I can't get the loop the stop. It keeps repeating the same string pattern over and over and over.
到目前为止,您的代码询问扫描仪是否有更多项目。但你从不消费它们。所以在你的循环中你需要调用类似
的东西String currentItem = myScanner.next();