System.out.println(); won't write in my if statement with stages

263 Views Asked by At

I'm trying to make a text based adventure story with options and different scenarios. When I use if(stage == *) it does not activate sysout messages, only in my switch statements or it adds it after I give an input.

private static int stage = 0;
Scanner in = new Scanner(System.in);
String opt = in.next().toLowerCase();

if(stage == 0) {
    System.out.println("Do you go left or right?");
    switch(opt) {
        case "right":
            System.out.println("Swamp, you go through the thicket and move forward.");
            stage = 10;
            break;
        case "left":
            System.out.println("You find an open field with flowers all over.");
            stage++;
            break;
    }
}
1

There are 1 best solutions below

1
On

You are reading from input before to ask the question, that's why your question is printed after you give an input.

String opt = in.next().toLowerCase(); should go after System.out.println("Do you go left or right?"); because reading from input is blocking