问题描述
我正在尝试编写一个程序,该程序需要一个名字和金额,并发送一个简短的谢谢字母和循环,直到nextLine退出
循环很好,但由于某种原因在第二个循环中程序跳过String输入并直接进入Int ..
boolean keepgoing = true;
while(keepgoing = true)
{
out.println(人名是什么?);
String personname = keyboard.nextLine();
out.println(他们捐了多少钱?);
int donation = keyboard.nextInt ();
out.println(亲爱的+人名+);
out.println(谢谢你的捐款+捐赠+\ n );
out.println(问候,詹姆斯);
if(personname.equals(quit))
{
keepgoing = false;
}
我尝试了什么:
不知道是什么可能是问题,这似乎是一个奇怪的怪癖。
I'm trying to write a program that takes a name and amount of money and sends a short thankyou letter and loops until nextLine is "quit"
Its looping just fine, but for some reason on the second loop the program skips the String enter and goes straight to Int..
boolean keepgoing = true;
while (keepgoing = true)
{
out.println("What is the persons name?");
String personname = keyboard.nextLine();
out.println("How much did they donate?");
int donation = keyboard.nextInt();
out.println(" Dear " + personname + "");
out.println("Thankyou for your donation of " + donation + "\n");
out.println("Regards, James");
if(personname.equals("quit"))
{
keepgoing = false;
}
What I have tried:
No idea what could be the problem, this seems like a strange quirk.
推荐答案
这篇关于而循环问题.. Java初学者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!