【发布时间】:2021-10-01 04:21:51
【问题描述】:
我开发了一个字符排序器,我想在每次字符串排序后提示用户输入一个新字符串。我遇到的问题是扫描仪不断扫描用户的第一个输入。如果我使用scanner.next(),它不会计算输入末尾的空白,这不是解决方案。
这是 while 循环的开始。代码完成后,它会再次从“inputText”开始。
inputText:
while(keepSorting){
System.out.print("Please input the string to be sorted: " );
c.settingInput(s.nextLine());
System.out.println(" ");
int option;
more code
.... }
【问题讨论】:
-
nextLine会给你下一行。不知道你的意思。 -
你想留在while循环中吗?如果是这样,一定有一些代码行重定向到
inputText: -
如果你需要帮助调试你的代码,那么你需要发布一个minimal reproducible example。
标签: java