mardi 23 mai 2017

If statement not working correctly? Outputting the wrong thing [duplicate]

This question already has an answer here:

 case "B" :
                            System.out.println(" ");
                            System.out.println(line3);
                            System.out.println(" ");
                            System.out.println("The riddle is: The more you take, the more you leave behind. What am I?");
                            GuessRoomB = input.nextLine();
                            if(GuessRoomB == "Footsteps")

                                System.out.println("Correct! You may now continue to the final room. Good Luck!");

                            else
                                System.out.println(" ");
                                System.out.println("Wrong! [G A M E O V E R]");
                                System.exit(0);

                            break;

Currently i'm creating a simple text based game for finals in my Comp. Sci class and I can't quite figure out whats wrong with this particular if statement. When I run the program and answer the question when prompted, even if i get the question right it always defaults to "Wrong! [G A M E O V E R]" I'm not sure what exactly i'm doing wrong and any help would be greatly appriciated.

Aucun commentaire:

Enregistrer un commentaire