0

i dont find a solution to this problem. The first scan.nextLine() doesnt wait for input. It prints out "Deutsch: English:" an then waits for input. How do i stop the scanner from printing the second System.out.print ?

What i've found while searching for solutions was, to add a scan.nextLine() after "array.add(vk1)". That didnt work. Also i tried using two Scanners, that didnt work too.

If i use just scan.next() it works well, but i want to scan words like "to run" which has whitespace.

greetings

while(a){
            System.out.println("1. Vokabel eingeben\n"+"2. Beenden");
            java.util.Scanner scan = new java.util.Scanner(System.in);

            int b = scan.nextInt();
            if (b == 1){
                System.out.print("Deutsch: ");
                String vk1 = scan.nextLine();
                array.add(vk1);

                System.out.print("English: ");
                String vk2 = scan.nextLine();
                array.add(vk2);
            }
MarkyMark
  • 9
  • 1
  • I don't understand what you would like to do, but you shouldn't declare your Scanner on a `while`. Put `java.util.Scanner scan = new java.util.Scanner(System.in);` outside the `while(a)` – Mistalis Jun 14 '16 at 12:50
  • i want the while loop to ask for an input, then wait for input. It should be like: "Deutsch: [input here]" and then "English: [input here]" but instead i get "Deutsch: English: [input here] " an then it waits for input. – MarkyMark Jun 14 '16 at 13:08

0 Answers0