Nic*_*eux 0 java string if-statement equals
我的java程序,下面显示的部分,似乎停留在if("".equals)行.while循环继续,尽管if语句中的选项不会最终运行.因此,不是打印出新数据(在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;
}
}
Run Code Online (Sandbox Code Playgroud)
您的语句后面会有一个分号while,Java会将其视为while循环的整个主体,从而产生无限循环.然后它永远不会到达它下方的大括号中.
删除分号,因此您在大括号中的预期块实际上将是while循环块.
| 归档时间: |
|
| 查看次数: |
105 次 |
| 最近记录: |