You could take the first character from Scanner.next:

char c = reader.next().charAt(0);

To consume exactly one character you could use:

char c = reader.findInLine(".").charAt(0);

To consume strictly one character you could use:

char c = reader.next(".").charAt(0);
Answer from ShihabSoft on Stack Overflow
🌐
Reddit
reddit.com › r/learnprogramming › .nextline() in java
r/learnprogramming on Reddit: .nextLine() in Java
April 23, 2022 -

Input:

import java.util.Scanner;
class HelloWorld {
    public static void main(String[] args) {
Scanner abc = new Scanner(System.in);
        System.out.println("What's your name?");
        String name = abc.nextLine();
        System.out.println("How old are you?");
        int age = abc.nextInt();
        System.out.println("What is your favourite movie?");
        String movie = abc.nextLine();
        System.out.println("What's your contact number?");
        int phone = abc.nextInt();
        System.out.print("Your name is " + name + ".You're " + age + ".Your favourite movie is " + movie + ", and your contact is " + phone);
    }
}

The above input is giving the following output in all my IDEs:

What's your name?
Zachary Hach // input by me
How old are you?
23 // input by me
What is your favourite movie?
What's your contact number?
1234567890 // input by me
Your name is Zachary Hach.You're 23.Your favourite movie is , and your contact is 1234567890

Now, my question is why the system didn't ask me to input my favorite movie. It skips the movie part and goes straight to the contact number. Why is this happening? Why won't it let me input my favorite movie? It works fine with the name part though which uses the same code as the movie part.

Discussions

next() vs nextLine()
As the other comment says, it is one of the issues you face when you mix all the inputs up. nextLine with the nextDouble before it produces the logical error you have because nextLine will just skip over the line. Nevertheless, not to be off-topic, but close your scanner! More on reddit.com
🌐 r/learnjava
5
5
March 7, 2019
java - Understanding Scanner's nextLine(), next(), and nextInt() methods - Stack Overflow
The escape sequences you are talking about are in Java source code, in string and character literals. They may >>represent<< a CR or NL or ... other characters. ... Save this answer. ... Show activity on this post. ... nextline() - It read a line until it gets newline (here - after read previous ... More on stackoverflow.com
🌐 stackoverflow.com
Reading input from user - Java - Code with Mosh Forum
nextLine() returns everything from the current position (or marker) - including whitespace - until it finds a newline character (or the end of the String, whichever comes first). More on forum.codewithmosh.com
🌐 forum.codewithmosh.com
0
September 9, 2022
java - Scanner is skipping nextLine() after using next() or nextFoo()? - Stack Overflow
But since line separators after reading the number from the console are found immediately in Scanner's cache, it returns empty String, meaning that Scanner was not able to find any character before those line separators (or end of stream). BTW nextLine also consumes those line separators. More on stackoverflow.com
🌐 stackoverflow.com
🌐
W3Schools
w3schools.com › java › ref_scanner_nextline.asp
Java Scanner nextLine() Method
The nextLine() method returns a string containing all of the characters up to the next new line character in the scanner, or up to the end of the scanner if there are no more new line characters.
🌐
Scaler
scaler.com › home › topics › nextline() in java
nextLine() in Java - Scaler Topics
July 14, 2024 - This is because, after we stored the value in the word and we pressed enter, the extra change in line was buffered as input and when the nextLine() method started searching for its input, it gets the extra change in line in buffer, and just because there is no character before the extra change in line, the nextLine() method stores the blank value in the variable and prints a blank space.
🌐
Educative
educative.io › answers › what-is-scannernextline-in-java
What is Scanner.nextLine() in Java?
The Scanner.nextLine() is a method in the Java Scanner class that returns a line of text that is read from the scanner object. This method can be used to read an entire line of text or to read input until a particular character or sequence is ...
🌐
CodeGym
codegym.cc › java blog › java io & nio › is there nextchar() in scanner class in java?
Is there nextChar in Scanner Class in Java?
October 11, 2023 - Taking character input in Java isn’t as simple as taking input as a string or integer. The Scanner class in Java works with nextInt(), nextLong(), nextDouble(), etc. However, it does not support nextChar in Java, which makes taking character input slightly more complicated.
🌐
CompleteEra
completeera.com › javas-nextline-and-charat-how-to-handle-input-correctly
Java’s `nextLine()` And `charAt()`: How To Handle Input Correctly - CompleteEra
May 5, 2026 - Fix: Add a dummy `nextLine()` to consume the leftover newline: “`java int num = scanner.nextInt(); scanner.nextLine(); // Consumes “\n” String input = scanner.nextLine(); // Now reads actual input “` The `charAt()` method throws `StringIndexOutOfBoundsException` if the index is out of bounds.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › scanner-nextline-method-in-java-with-examples
Scanner nextLine() method in Java with Examples - GeeksforGeeks
July 11, 2025 - Java Collection · Last Updated : 11 Jul, 2025 · The nextLine() method of java.util.Scanner class advances this scanner past the current line and returns the input that was skipped.
🌐
W3schools
w3schools.dev › java › ref_scanner_nextline.asp
Java Scanner nextLine() Method - W3Schools
The nextLine() method returns a string containing all of the characters up to the next new line character in the scanner, or up to the end of the scanner if there are no more new line characters.
🌐
freeCodeCamp
freecodecamp.org › news › java-scanner-nextline-call-gets-skipped-solved
Java scanner.nextLine() Method Call Gets Skipped Error [SOLVED]
August 26, 2022 - When the third scanner.nextLine() is called, it finds the enter or newline character still existing in the input buffer, mistakes it as the input from the user, and returns immediately.
🌐
Reddit
reddit.com › r/learnjava › next() vs nextline()
r/learnjava on Reddit: next() vs nextLine()
March 7, 2019 -

Here's the code I'm referring to: https://paste.ofcode.org/ARGhGxyDuLSPrehfYWUgLu

in my CSC class (its a low level java class) we were assigned with the task of essentially filling in code based a lot of gaps and comments that were given to us by the teacher. The above code was my result

When I run this code (via eclipse) it runs fine up to line 30, outputs line 30 - but then line 31 doesn't give me a field to type in any input at the command line. The entire program just runs as if line 31 doesn't exist.

However, if I change line 31 to repeat = input.next(); - it works perfectly fine and allows me to type in input.

Why is this? I don't see any reason why repeat = input.nextLine(); wouldn't at least give me a field to type at the command line.

🌐
Baeldung
baeldung.com › home › java › java string › adding a newline character to a string in java
Adding a Newline Character to a String in Java | Baeldung
May 11, 2024 - In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.
🌐
GeeksforGeeks
geeksforgeeks.org › java › scanner-class-in-java
Scanner Class in Java - GeeksforGeeks
Use nextLine() to read a full string/line. Use next().charAt(0) to read a single character.
Published: May 27, 2026
Top answer
1 of 2
6

nextLine() reads the remainder of the current line even if it is empty.

Correct.

nextInt() reads an integer but does not read the escape sequence "\n".

Correct1.

next() reads the current line but does not read the "\n".

Incorrect. In fact, the next() method reads the next complete token. That may or may not be the rest of the current line. And it may, or may not consume an end-of line, depending on where the end-of-line is. The precise behavior is described by the javadoc, and you probably need to read it carefully for yourself in order that you can fully understand the nuances.

So, in your example:

  1. The nextInt() call consumes the 2 character and leaves the position at the NL.

  2. The next() call skips the NL, consumes H and i, and leaves the cursor at the second NL.

  3. The nextLine() call consumes the rest of the 2nd line; i.e. the NL.


Note that the above assumes that you are using the default delimiter. (As your example does.) If you change the scanner's delimiter by calling one of the useDelimiter(...) methods, you can cause (for example) next() to return newline characters as part of a token.


1 ... except that your terminology is wrong. When the data is being read, it is not an escape sequence. It is an end-of-line sequence that could consist of a CR, a NL or a CR NL depending on the platform. The escape sequences you are talking about are in Java source code, in string and character literals. They may >>represent<< a CR or NL or ... other characters.

2 of 2
4

If your input is 2 hello hi

nextInt() - just read the next token as a int (Here - it is 2) otherwise it give error

next() - Just read the next token, (here - it is hello)

nextline() - It read a line until it gets newline (here - after read previous 2 hello input by nextInt, next; nextline read hi only because after that it finds a newline )

if input is

2 

Hi 

Hello 

nextInt, next is same for above discussion .

In nextline(), it finds newline after completing the input Hi read by next(). So, nextline() stops to read input for getting the newline character.

🌐
Edureka
edureka.co › blog › nextchar-in-java
What is NextChar in Java and How to Implement it? | Edureka
June 17, 2021 - The Scanner class provides nextXXX() ... nextBoolean(), etc. In order to derive a single character from the scanner, a call next().charAt(0) method which returns a single character can be called....
🌐
Code with Mosh
forum.codewithmosh.com › java
Reading input from user - Java - Code with Mosh Forum
September 9, 2022 - nextLine() returns everything from the current position (or marker) - including whitespace - until it finds a newline character (or the end of the String, whichever comes first).
🌐
DEV Community
dev.to › sbu_05 › reading-an-string-after-an-integer-4jbp
Reading a String after an Integer - DEV Community
March 12, 2021 - In other words, when java reads a String and it comes across the return character, java does not insert the characters "\n" into the text, instead it use it to format text by moving what ever is left of the string onto the next line. What I'm trying to get across is that the return character will be the last character in the string of an input. Therefore, the Scanner will consider everything before the return character as the actual input. The nextLine() method can easily convert the input to a string because that is the data type that it came in.
🌐
Reddit
reddit.com › r › javahelp › wiki › scanner
r/javahelp FAQ: Java Scanner nextLine() Issue
April 18, 2022 - The nextLine() method does not put the '\n' character back at the head of the stream; instead, it discards it.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-Scanner-next-vs-nextLine-methods-Whats-the-difference
Java Scanner next() vs nextLine() methods: What's the difference?
The difference between the Java Scanner’s next() and nextLine() methods is that nextLine() returns every character in a line of text up to the line separator, excluding the separator, while next() returns the next token according to the Scanner's ...
Published: January 24, 2026