When you read in the year month day hour minutes with something like nextInt() it leaves rest of the line in the parser/buffer (even if it is blank) so when you call nextLine() you are reading the rest of this first line.

I suggest you call scan.nextLine() before you print your next prompt to discard the rest of the line.

Answer from Peter Lawrey on Stack Overflow
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-String-input-with-the-Scanner-class
Java Scanner String input example
Learn how next(), nextLine(), and hasNext() process user input, including whitespace tokenization and complete-line reading. ... import java.util.Scanner; public class ScannerUserInput { public static void main(String[] args) { // String input with the Java Scanner System.out.println("How old are you?"); Scanner stringScanner = new Scanner(System.in); String age = stringScanner.next(); System.out.println(age + " is a good age to be!"); } }
Published: April 20, 2026
🌐
W3Schools
w3schools.com › java › java_user_input.asp
Java User Input (Scanner class)
In the example below, we use different ... Scanner(System.in); System.out.println("Enter name, age and salary:"); // String input String name = myObj.nextLine(); // Numerical input int age = myObj.nextInt(); double salary = myObj.nextDouble(); ...
Discussions

I have a problem reading string input using the scanner in java - Stack Overflow
I have an issue reading the string,The scanner read the Integer and the double and it show's the output without reading the string. I need your help. public static void main(String[] args) { More on stackoverflow.com
🌐 stackoverflow.com
java.util.scanner - How can I read input from the console using the Scanner class in Java? - Stack Overflow
Basically, all I want is have the scanner read an input for the username, and assign the input to a String variable. ... A simple example to illustrate how java.util.Scanner works would be reading a single integer from System.in. More on stackoverflow.com
🌐 stackoverflow.com
Scanner Not Working in a While Loop
Hiya - this is a weird Java error*. My students ran into this as well. Here's the fix: After int ava = scan.nextInt(); Add: scan.nextLine(); That will clear the scanner buffer. *Apparently it is a feature, not a bug. EDIT: The line above this one. More on reddit.com
🌐 r/learnjava
17
23
May 28, 2020
How do I get multiple words of input from a user to store in one variable?
My guess is it's related to Scanner#newLine() reading the newline character so Scanner#skip() might work: https://stackoverflow.com/a/59388668/ I think you can use next() if you assume that the full name is two words. More on reddit.com
🌐 r/javahelp
6
17
May 1, 2020
People also ask

What’s the best way to store multiple string inputs in Java for later use?
When handling multiple string inputs, especially if the count isn’t fixed, use dynamic data structures like ArrayList. After reading strings using scanner.nextLine() or splitting a line into tokens, add each entry to the list. This allows you to easily perform operations like searching, filtering, or mapping over the input later in the program.
🌐
upgrad.com
upgrad.com › home › blog › software development › how to take multiple string input in java using scanner: a step-by-step guide
Multiple String Input in Java Using Scanner: Step-by-Step Guide
How do you handle exceptions or errors while taking multiple string inputs using Scanner?
Scanner input operations can throw exceptions such as NoSuchElementException or IllegalStateException if input is prematurely closed or unavailable. Although strings rarely cause format issues like numbers do, you should still handle unexpected inputs or stream closure gracefully. Using try-catch blocks around input reading logic ensures your program can inform users of errors and request re-entry instead of crashing. This practice is critical in interactive applications like user registration or command-line tools, where reliability improves user trust and reduces debugging time.
🌐
upgrad.com
upgrad.com › home › blog › software development › how to take multiple string input in java using scanner: a step-by-step guide
Multiple String Input in Java Using Scanner: Step-by-Step Guide
How can I efficiently store multiple string inputs read by Scanner for further processing?
After capturing multiple strings, especially when the number is dynamic, using collections such as ArrayList or LinkedList provides flexibility for storage and manipulation. For example, after splitting a line into tokens or reading tokens one by one in a loop, you can add each string to an ArrayList. This is beneficial in applications like search engines, where input keywords need to be stored, filtered, or searched. Collections allow you to apply operations like sorting, filtering, or mapping strings, improving your program’s scalability and performance.
🌐
upgrad.com
upgrad.com › home › blog › software development › how to take multiple string input in java using scanner: a step-by-step guide
Multiple String Input in Java Using Scanner: Step-by-Step Guide
🌐
Scaler
scaler.com › home › topics › string input in java
String Input in Java - Scaler Topics
May 4, 2023 - The Scanner class's next() method in Java is used to read the input before the whitespace is detected. next() method is unable to read two words separated by whitespace. After reading the input, it keeps the pointer in the same line. ... Next complete string value is returned by next() method.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › string input in java
How to Take String Input in Java - Methods Explained | upGrad
June 22, 2025 - The program prompts the user to enter a word by displaying the message "Enter a word: ". The next() method of the Scanner object is used to read the next word from the input as a string and store it in the variable word.
🌐
TechVidvan
techvidvan.com › tutorials › taking-string-input-in-java
How to take Input in Java Using Scanner Class and BufferedReader Class - TechVidvan
June 24, 2020 - Java next() method can read the input before space encounters. It cannot read two words separated by space. It retains the cursor in the same line after reading the input. ... Next method returns the next complete token from this scanner.
Find elsewhere
🌐
Upgrad
upgrad.com › home › blog › software development › how to take multiple string input in java using scanner: a step-by-step guide
Multiple String Input in Java Using Scanner: Step-by-Step Guide
July 7, 2026 - In this example, you will learn how to use the next() method of the Scanner class to read multiple strings one by one. The next() method reads input token by token, stopping at whitespace, making it ideal for capturing individual words entered sequentially...
🌐
BeginnersBook
beginnersbook.com › 2024 › 06 › how-to-take-string-input-in-java
How to take String Input in Java
June 9, 2024 - Don’t forget to import ... for string input System.out.println("Enter a string:"); // Read the user input using nextLine() method String input = scanner.nextLine(); // Print the input string System.out.println("User entered: " + input); // Close the Scanner object ...
🌐
Codefinity
codefinity.com › courses › v2 › 8bdbdd9f-a2a1-4a34-a8f4-240fb6f735eb › 07dee2a0-3f38-4948-8e3b-6a4d062c0689 › 0700e32d-ddf8-4ab2-b5ff-c9065b6c3bf6
Learn Reading Strings from User Input | Getting Started with Scanner
Main.java · 12345678910111213 ... " + name + "!"); } } The nextLine() method reads all characters entered by the user until the Enter key is pressed, returning the entire line as a String....
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-Scanner-User-Input-example-String-next-int-long-char
Java Scanner User Input Example
Use the Java user input in your program. Found in the java.util package, Java’s Scanner class can read input from the command line and return it as a String, BigDecimal or any one of Java’s eight primitive types.
Published: May 15, 2026
🌐
Zero To Mastery
zerotomastery.io › blog › java-scanner
Beginner's Guide To Java Scanner (With Code Examples) | Zero To Mastery
String name = scanner.nextLine(); → Reads an entire line of text from the user · System.out.println("Hello, " + name + "!"); → Prints a personalized greeting using the user’s input ... So let’s show you how to set it up. Since Scanner isn’t automatically available in Java, the first thing you need to do is import it.
🌐
SourceBae
sourcebae.com › home › how to take multiple string input in java using scanner?
How to Take Multiple String Input in Java Using Scanner? - SourceBae
August 21, 2025 - ... Prompt for Input: Display a prompt message to inform the user about the expected input. This step is essential for clarity and user-friendliness. ... Read String Inputs: To read a string input, use the next() method of the Scanner object.
🌐
GeeksforGeeks
geeksforgeeks.org › java › scanner-class-in-java
Scanner Class in Java - GeeksforGeeks
Scanner is a predefined class in Java used to take input from the user. It is present in the java.util package and supports different types of input such as integers, strings, float values, and characters.
Published: May 27, 2026
🌐
Baeldung
baeldung.com › home › java › java string › how to take input as string with spaces in java using scanner?
How to Take Input as String With Spaces in Java Using Scanner? | Baeldung
November 29, 2023 - String input = "Michael Jackson, Whitney Houston, John Lennon\n"; Scanner sc = new Scanner(input); String[] names = sc.nextLine().split(", "); assertArrayEquals(new String[] { "Michael Jackson", "Whitney Houston", "John Lennon" }, names); The test above shows we’ve stored the three names in a string array correctly. The split() with the separator pattern approach can handle values with a custom separator. However, as arrays have fixed sizes in Java, merging arrays can be slow if the scanner input has multiple lines.
🌐
DEV Community
dev.to › realedwintorres › tutorial-accepting-string-input-in-java-4j9o
Tutorial: Accepting String Input in Java - DEV Community
October 31, 2021 - import java.util.Scanner; public class Example { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("What's your name? "); //NEW } } Since System.out.print() does not output a newline character, ...
🌐
DataFlair
data-flair.training › blogs › how-to-take-string-input-in-java
How to Take String Input in Java? - DataFlair
May 30, 2026 - Code to understand Scanner Class ...rintln("Enter a String"); String str = sc.next(); System.out.println("The String input using Scanner class is: " +str); } }...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Scanner.html
Scanner (Java Platform SE 8 )
July 21, 2026 - A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different types using the various next methods. For example, this code allows a user to read a number from System.in:
🌐
Java Made Easy!
java-made-easy.com › java-scanner.html
Java Input Using Java Scanner
Okay, so now the input someone types in will be stored in your String variable from the Java Scanner. You can use that variable to now output back the line of text. The program will just echo whatever is typed in. You should be able to output the string on your own, because you should have learned how to already.