gpt4 book ai didi

java - 在Java中,为什么会收到错误消息,提示我是否需要其他?

转载 作者:行者123 更新时间:2023-12-02 11:07:25 27 4
gpt4 key购买 nike

因此,我要在6个小时内完成这个庞大的项目,尽管我还没有对将要读取的所有文件进行编码,但是我正在设置所有if语句。您会看到我正在建立一个用户在其中输入3个数字的数据库,作为返回,该文件将以输出格式读取文件。到目前为止,一切似乎都很好,除了底部显示的其他内容:

 if (choose == 4) //enemies from the original Kingdom Hearts II
{
System.out.println("Please select the enemy race you wish to view:");
System.out.println("1. Heartless");
System.out.println("2. Nobodies");
int enemies_4 = kH.nextInt();

if (enemies_4 == 1) //Allows the user to select which kinds of Heartless to view from Kingdom Hearts II.
{
System.out.println("Please type the number which corresponds to the Heartless enemy type.");
System.out.println("1. Pureblood");
System.out.println("2. Emblem");
System.out.println("3. Gummi");
int heartless_4 = kH.nextInt();

if (heartless_4 = 1) //allows the user to view Pureblood Heartless from KH2
{

}

if (heartless_4 == 2) //allows the user to view the Emblem Heartless in KH2
{

}

else
{
System.out.println("Please enter a number which corresponds to one of the Heartless types KH2.");
}
}


if (enemies_4 == 2) //allows the user to view all of the Nobodies in KH2
{
System.out.println("Please type the number which corresponds to the Nobody enemy type.");
System.out.println("1. Lower");
System.out.println("2. Gummi");
int nobodies_4 = kH.nextInt();

if (nobodies_4 == 1) //Gives the selection of the Lower Nodies in Kingdom Hearts II.
{

}

if (nobodies_4 == 2) //Gives the selection of the Gummi Nobodies, which are ONLY in Kingdom Hearts II
//(as well as the Final Mix version of it).
{

}

if (nobodies_4 == 3) //Give the selection of all he members of Organization XIII which appear in
//Kingdom Hearts II.
{

}

else
{
System.out.println("Please enter a number which corresponds to one of the Nobody types KH2.");
}

else
{
System.out.println("Please input a number which corresponds to an enemy.");
}
}

该错误表明应该是else if,但是当我将if放在它旁边时,我会自动得到100错误。我该怎么办?

最佳答案

如果所有if块都是互斥的,则始终使用if-else是一个好习惯。话虽如此,以上错误是由于缺少“}”

if (choose == 4) //enemies from the original Kingdom Hearts II
{
System.out.println("Please select the enemy race you wish to view:");
System.out.println("1. Heartless");
System.out.println("2. Nobodies");
int enemies_4 = kH.nextInt();

if (enemies_4 == 1) //Allows the user to select which kinds of Heartless to view from Kingdom Hearts II.
{
System.out.println("Please type the number which corresponds to the Heartless enemy type.");
System.out.println("1. Pureblood");
System.out.println("2. Emblem");
System.out.println("3. Gummi");
int heartless_4 = kH.nextInt();

if (heartless_4 = 1) //allows the user to view Pureblood Heartless from KH2
{

}

if (heartless_4 == 2) //allows the user to view the Emblem Heartless in KH2
{

}

else
{
System.out.println("Please enter a number which corresponds to one of the Heartless types KH2.");
}
}


if (enemies_4 == 2) //allows the user to view all of the Nobodies in KH2
{
System.out.println("Please type the number which corresponds to the Nobody enemy type.");
System.out.println("1. Lower");
System.out.println("2. Gummi");
int nobodies_4 = kH.nextInt();

if (nobodies_4 == 1) //Gives the selection of the Lower Nodies in Kingdom Hearts II.
{

}

if (nobodies_4 == 2) //Gives the selection of the Gummi Nobodies, which are ONLY in Kingdom Hearts II
//(as well as the Final Mix version of it).
{

}

if (nobodies_4 == 3) //Give the selection of all he members of Organization XIII which appear in
//Kingdom Hearts II.
{

}

else
{
System.out.println("Please enter a number which corresponds to one of the Nobody types KH2.");
}
} // You were missing this
else
{
System.out.println("Please input a number which corresponds to an enemy.");
}
}

关于java - 在Java中,为什么会收到错误消息,提示我是否需要其他?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22005230/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com