我的java程序,下面显示的部分,似乎卡在if(“”。equals)行上。虽然if语句中的选项不是最终运行,但while循环仍在继续。因此,不是打印出新数据(在else下)或打印出信息(在默认情况下),它只是不断要求新的输入。
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;
}
}
答案 0 :(得分:8)
您的while
语句后面紧跟着一个分号,Java会将其视为while
循环的整个主体,从而导致无限循环。然后它永远不会到达它下方的大括号中。
删除分号,因此大括号中的预期块实际上是while
循环块。