Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java While循环打印_Java - Fatal编程技术网

Java While循环打印

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的值。嗯,它

为什么我的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的值。嗯,它不会进入块在进入循环之前检查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;
}