[Solved] The while loop double prints first before entering a value [closed]


It’s because you are using sc.nextInt() to get input from the user and it doesn’t consume the line so when you use switcher = sc.nextLine(); it still reads the number that the user entered before.

You can add this after catcher = sc.nextInt(); to consume the line:

    if (sc.hasNextLine()){
        sc.nextLine();
    }

Or alternatively you could use:

catcher = Integer.parseInt(sc.nextLine());

To convert the user input to an integer value and it will also work.

1

solved The while loop double prints first before entering a value [closed]