我的java程序(下面有问题的部分)似乎被困在if("".equals)行上。虽然if语句中的两个选项都没有运行,但while循环仍在继续。因此,它不会打印新数据(在“否则”下)或打印出信息(在默认情况下),而只是继续请求新的输入。
System.out.println("Type in government type. Enter '?' and click enter for list of gov types.");
while(playerSelection==false);
{
input = fileinput.nextLine();
if("?".equals(input))
{
System.out.println("despotic_monarchy, administrative_monarchy, constitutional_monarchy, despotic_monarchy, enlightened_despotism, feudal_monarchy, revolutionary_empire\n"+
"administrative_republic, beauracratic_despotism, constitutional_republic, republican_dictatorship, merchant_republic, noble_republic, revolutionary_republic\n"+
"papal_government\n"+
"steppe_horde, tribal_democracy, tribal_despotism, tribal_federation");
}
else
{
fileLines[lGov[nationSelected]] = " " + input;
System.out.println(fileLines[lGov[nationSelected]]);
playerSelection=true;
}
}发布于 2013-08-29 18:16:47
在while语句之后有一个分号,它将作为while循环的整个体来处理,从而产生一个无限循环。然后,它将永远不会到达在它下面的支撑块。
移除分号,所以大括号中的预期块实际上是while循环块。
https://stackoverflow.com/questions/18518216
复制相似问题