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
Here’s the output of the updated Scanner String input processing program: How old are you? 20 30 40 50 20 is a good age to be! 30 is a good age to be! 40 is a good age to be! 50 is a good age to be! As we have seen, the Scanner’s next() method consumes a line of text, tokenizes the input based on any whitespace, and then iteratively loops through each individual item.
Published: April 20, 2026
🌐
W3Schools
w3schools.com › java › java_user_input.asp
Java User Input (Scanner class)
To use the Scanner class, create an object of the class and use any of the available methods found in the Scanner class documentation. In our example, we will use the nextLine() method, which is used to read Strings:
Discussions

Java Scanner String input - Stack Overflow
I'm writing a program that uses an Event class, which has in it an instance of a calendar, and a description of type String. The method to create an event uses a Scanner to take in a month, day, y... 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
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
Using Scanner to get a full string
It seems that you are having problems with java.util.Scanner The wiki here has a page The Scanner class and its caveats that explains common problems with the Scanner class and how to avoid them. Maybe this can solve your problems. Please do not reply because I am just a bot, trying to be helpful. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
7
1
February 24, 2024
People also ask

Can I use a file instead of the console to input strings?
Yes, by constructing a Scanner object with a File object corresponding to the file we wish to read, we may use the Scanner class to read string input from a file. We would supply the File object to the Scanner constructor instead of System.in. Using this technique, we can read strings from a file and process them accordingly.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › string input in java
How to Take String Input in Java - Methods Explained | upGrad
Is it possible for me to accept several strings on a single line?
Yes, the next() method of the Scanner class can take several strings as input on a single line. This method reads the subsequent token from the input, a string of characters mostly separated by spaces. To read several strings entered on the same line, call the next() method multiple times.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › string input in java
How to Take String Input in Java - Methods Explained | upGrad
🌐
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 - You can supply text-based data through string input, which can then be processed, changed, or stored to meet your program's needs. Yes, the next() method of the Scanner class can take several strings as input on a single line.
🌐
GeeksforGeeks
geeksforgeeks.org › java › scanner-class-in-java
Scanner Class in Java - GeeksforGeeks
Use nextXYZ() methods for numeric inputs like nextInt(), nextShort(), etc. Use nextLine() to read a full string/line. Use next().charAt(0) to read a single character. Always close the Scanner object after use.
Published: May 27, 2026
Find elsewhere
🌐
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.
🌐
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 ... 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 after ...
🌐
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.
🌐
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 - Usually, we’d use lists over arrays in Java. So next, let’s adjust the Scanner’s delimiter and store the names in a list using Scanner’s next() method. We’ve learned to use the useDelimiter() method to set a custom delimiter pattern. Since the separator of this input example is a comma and space, some of us may come up with the idea: useDelimiter(“, “). So next, let’s add one more name to the input and see if this idea works as expected: String input = new StringBuilder().append("Michael Jackson, Whitney Houston, John Lennon\n") .append("Elvis Presley\n") .toString(); Scanner sc = new Scanner(input); sc.useDelimiter(", "); List<String> names = new ArrayList<>(); while (sc.hasNext()) { names.add(sc.next()); } assertEquals(Lists.newArrayList("Michael Jackson", "Whitney Houston", "John Lennon", "Elvis Presley"), names);
🌐
Unstop
unstop.com › home › blog › how to take input in java | scanner class & more (+examples)
How To Take Input In Java | Scanner Class & More (+Examples)
February 27, 2025 - The Scanner Class: A part of the java.util package, the Scanner class is one of the most popular and beginner-friendly ways to take input in Java. It is widely used for parsing primitive types and strings from various input sources, including user input from the console.
🌐
DataFlair
data-flair.training › blogs › how-to-take-string-input-in-java
How to Take String Input in Java? - DataFlair
May 30, 2026 - Also, the Scanner class contains the nextLine() method, which allows user input in the form of a string. The signature of the nextLine() method is given by: ... The method returns the entered string from the input buffer.
🌐
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
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
🌐
DEV Community
dev.to › realedwintorres › tutorial-accepting-string-input-in-java-4j9o
Tutorial: Accepting String Input in Java - DEV Community
October 31, 2021 - Next, use the Scanner input variable to accept one string from the console: 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?
🌐
Medium
harish303.medium.com › how-to-take-string-input-in-java-d1f3bbfbe889
How to take String Input in Java. In Java, you can take string input… | by Harish Anbalagan | Medium
May 21, 2025 - How to take String Input in Java In Java, you can take string input using the Scanner class. Here's how you do it: Step-by-Step: Take String Input in Java Import the Scanner class import …
🌐
Upgrad
upgrad.com › home › blog › software development › how to take multiple string input in java using scanner: a step-by-step guide
How to Take Multiple String Input in Java Using Scanner
July 7, 2026 - Handling multiple string input in Java involves reading several strings from the user, either together or one after another. Managing this input efficiently is essential to building reliable console applications. The Scanner class is the standard Java utility that simplifies reading input from the console.
🌐
C# Corner
c-sharpcorner.com › home › technologies › java › take input in java using scanner class with code
Take Input in Java using Scanner Class with Code
December 6, 2024 - Importing Scanner: The line import java.util.Scanner; imports the Scanner class, making it available for use in your program. Creating a Scanner Object: The statement Scanner scanner = new Scanner(System.in); creates a new instance of the Scanner class that reads input from the console. ... ...
🌐
Instanceofjava
instanceofjava.com › 2016 › 08 › java-user-input-scanner-class-program.html
How to take input from user in java using scanner - InstanceOfJava
Java.util.Scanner class provides lot of methods to take different typed of data from the user as input. Scanner class is final class in java like String class.
🌐
Tpoint Tech
tpointtech.com › how-to-take-string-input-in-java
Take String input in Java - Tpoint Tech
May 1, 2026 - The nextLine() method of Scanner class is used to take a string from the user. It is defined in java.util.Scanner class. The nextLine() method reads the text until the end of the line. After reading the line, it throws the cursor to the next line · The signature of the method is: