while(!A){
System.out.println ("You enter a room and look around, in it, you see three doors, a red door labeled A, a blue door labeled B, and a green door labeled C. Which door do you choose to go through? Enter, A, B, or C");
String correctdoor = scanner.next();
A = "A".equalsIgnoreCase(correctdoor);
System.out.println("You have chosen wrong! You have fallen into a pit! Lucky for you though, the pit is easy to climb out of and you return to the room....\n\n\n");
}
System.out.println("You progress through the door and find 5 light switches, you must turn them on in order to progress further. Enter the correct combination (using digits 1-5) here please. HINT - the 2nd and 4th numbers add up to the first number and the last number is NOT 5");
int lightcode = scanner.nextInt();
while (!(lightcode == 31425)){System.out.println ("That combination is incorrect");}
System.out.println ("The door unlocks and you go down a set of stairs");
嘿,回来再寻求更多帮助。更多关于我的文字游戏的问题
当用户输入b或c或任何其他值不是A时,while语句的工作方式是按预期工作,但是当它们放入A时,它会将它们带出while循环,但它仍然会打印出'您已选择错误'的字符串。我不知道为什么,但我确定你们可以告诉我为什么。
此外,如果我输入正确的数字,第二个循环完美工作,唯一的问题是,当我不这样做,它会告诉我'组合不正确',但它不会打印一次,它会一直打印它并不会停止,它的无休止的。我做错了什么?
也许我应该使用if语句?呃......不......那不会循环......呃。
PS我知道我说的最后一个数字的心不是5,但衣衫将其固定后
为什么不输入''A'选择了错误!为什么第二个'while'不会无限循环? – 2014-09-28 05:37:12
,因为A是正确的答案,它将它们带出循环。 – METEORITES 2014-09-28 05:38:34
您如何看待代码执行?如果一个声明在另一个声明之后出现,是否应该在其他声明之后执行? – 2014-09-28 05:40:14