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");
ねえ、また助けを求めて戻ってきて。
while ステートメントは、ユーザーが b または c または A 以外の値を入力すると意図したとおりに機能しますが、A を入力すると while ループから抜け出しますが、「間違った選択をした」という文字列が出力されます。理由はわかりませんが、理由を教えていただけると確信しています。
さらに、正しい番号を入力すると、2 番目のループは完全に機能します。唯一の問題は、そうしないと、「コンボが正しくありません」と表示されますが、一度印刷するだけでなく、印刷を続けて停止しないことです。その終わりのない。私は何を間違えましたか?
多分私はif文を使うべきですか?え…いや…ループしない…うーん。
ps最後の数字は5ではないと言ったことは知っていますが、投稿で修正してください