Java While循环打印
为什么我的while循环继续打印请输入stock lengthm: 代码: 输出:Java While循环打印,java,Java,为什么我的while循环继续打印请输入stock lengthm: 代码: 输出: Please enter stock length(mm): 4 Please enter quantities of this stock length: 4 Are you done? (y/n): Please enter stock length(mm): 使用sc.nextLine代替sc.nextLine 问题仍然存在=/@Liondancer请参见上文,如果它进入if块并检查done的值。嗯,它
Please enter stock length(mm): 4
Please enter quantities of this stock length: 4
Are you done? (y/n): Please enter stock length(mm):
使用sc.nextLine代替sc.nextLine
问题仍然存在=/@Liondancer请参见上文,如果它进入if块并检查done的值。嗯,它不会进入块在进入循环之前检查done的值。即使输入y或yes,也只会输入空格
Please enter stock length(mm): 4
Please enter quantities of this stock length: 4
Are you done? (y/n): Please enter stock length(mm):
String done = sc.next();
if (done.equalsIgnoreCase("y") || done.equalsIgnoreCase("yes")) {
System.out.println("breaking out of loop " + "Value of done: " + done)
break;
}