Change to String name = scanner.nextLine();
instead of String name = scanner.next();
See more on documentation here – next() and nextLine()
More Related Contents:
- Conditional Statement on Java7
- How to use java.util.Scanner to correctly read user input from System.in and act on it?
- java.util.NoSuchElementException – Scanner reading user input
- How to handle infinite loop caused by invalid input (InputMismatchException) using Scanner
- How can I read input from the console using the Scanner class in Java?
- Close a Scanner linked to System.in
- Scanner vs. BufferedReader
- How do I use a delimiter with Scanner.useDelimiter in Java?
- Why am I getting InputMismatchException?
- Scanner error with nextInt() [duplicate]
- Read CSV with Scanner()
- Scanner NoSuchElementException
- How do I keep a Scanner from throwing exceptions when the wrong type is entered?
- How to read multiple Integer values from a single line of input in Java?
- Java String Scanner input does not wait for info, moves directly to next statement. How to wait for info? [duplicate]
- Close Scanner without closing System.in
- How to use multiple Scanner objects on System.in?
- How to interrupt java.util.Scanner nextLine call
- Java scanner not going through entire file
- What does scanner.close() do?
- Scanner skipping every second line from file [duplicate]
- How to read a text file directly from Internet using Java?
- Java Scanner doesn’t wait for user input [duplicate]
- Why is hasNext() False, but hasNextLine() is True?
- How to use multiple Scanner objects on System.in in Java?
- Scanner is never closed
- Exception in thread “main” java.io.FileNotFoundException: Error
- Why can’t I enter a string in Scanner(System.in), when calling nextLine()-method?
- Java Scanner class reading strings
- How to put a Scanner input into an array… for example a couple of numbers