0

I have multiple Scanner methods to save input, but when I execute the code and enter for example "word 5", the Scanner reads input for the next Scanner method as well. How can I stop that?

    ...
    correctInput = true;
    for (int i = 0; i < runnI; i++) {
        System.out.println(".....");
        array1[i] = sc.next();

        System.out.println(".....");
        do {
            try {
                array2[i] = sc.nextDouble();
                correctInput= false;
            } catch (InputMismatchException e) {
                System.out.println("Wrong");
                sc.next();
            }
        } while (correctInput);
    }

1 Answers1

0

So guys, I found out that it works, when I write sc.nextLine() before the first System.out.println() and array1[i] = sc.nextLine() after it