由于某种原因不读取最后一个输入,但读取其他输入
(使用java)
我对这个问题的旧解释很糟糕,所以我会重新表述它。基本上在代码的末尾,它应该检查用户是否想要重新运行程序。 Y == 重复。 N == 结束程序。那么为什么这段代码不起作用呢?它与其他检查正在执行的操作相同,但看起来它几乎跳过了最后两个 if 语句。怎么了?
String loopy = in.nextLine();
in.nextLine();
if(loopy.equals("Y")){
for(int count = 0;count<5;count++)
{
System.out.println("");
}
}
if(loopy.equals("N"))
{
break;
}
}
System.out.println("You have chosen to exit the program. Program Finished");
}}
(Using java)
My old explanation of the problem is terrible so I'll re word it. Basically at the end of the code it should check if the user wants to rerun the program. Y == Repeat. N == End program. So why is this code not working? It is the same as what the other checks are doing but it almost seems like it skips those last two if statements. What is wrong?
String loopy = in.nextLine();
in.nextLine();
if(loopy.equals("Y")){
for(int count = 0;count<5;count++)
{
System.out.println("");
}
}
if(loopy.equals("N"))
{
break;
}
}
System.out.println("You have chosen to exit the program. Program Finished");
}}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
只需交换这两行的顺序,您的代码就会运行良好
:
Just swap the order of these two lines and your code will run well:
Make it:
看起来您正在阅读最后一个问题的答案两次:
It looks like you're reading the answer to the last question twice:
你的 while 循环永远运行,
永远循环,改变 true 来检查最后一个问题的答案是否是肯定的。
your while loop runs forever,
loops forever, change true to check whether the answer to the last question is yes.