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