当我在扫描仪中输入任何数字时,它会返回else语句ALWAYS,并且我陷入了无限循环。谁能帮我吗?我需要创建storyChoice变量String,而不是Int,因为我计划在需要用户输入为字符串的语句中添加更多其他if语句。
String storyChoice = keybd.next();
//This loop checks the scanner to see if the user has inputted an
//appropriate answer, as soon as the user inputs an appropriate answer
//The while loop terminates.
while(storyChoice != "1"|| storyChoice != "2" || storyChoice != "3")
{
if(storyChoice == "1")
{
Sword story = new Sword();
story.intro();
break;
}
else if (storyChoice == "2")
{
System.out.println("Not coded yet, so stay tuned!");
break;
}
else if(storyChoice == "3")
{
System.out.println("Not coded yet, so stay tuned!");
break;
}
else
{
System.out.println("Please choose an appropriate answer");
storyChoice = keybd.next();
}
}
谢谢。