One of the simplest ways is to use a Scanner object as follows:

import java.util.Scanner;

Scanner reader = new Scanner(System.in); // Reading from System.in
System.out.println("Enter a number: ");
int n = reader.nextInt(); // Scans the next token of the input as an int
// Once finished
reader.close();
Answer from Marco Aviles on Stack Overflow
🌐
W3Schools
w3schools.com › java › java_user_input.asp
Java User Input (Scanner class)
The Scanner class is used to get user input, and it is found in the java.util package. 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:
🌐
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
Discussions

How to get the user input in Java? - Stack Overflow
I attempted to create a calculator, but I can not get it to work because I don't know how to get user input. How can I get the user input in Java? More on stackoverflow.com
🌐 stackoverflow.com
java - How to get user input with string - Stack Overflow
My project is very similar to the famous ATM problem. I have to create a hotel check in/check out system. I have to get the user input for the last name and confirm it. However when I try to return... 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
User input program
Format your code properly Here's the logic: you want to get an input from the user, so that you know what data type you should be handling. then, ask another input from the user, which is the data itself. once you get it, you want to determine if the input need to be converted to int/double, or just stay as String. You can try to figure out how to correct your code first, then if you had troubles, we can continue to solve them. More on reddit.com
🌐 r/learnjava
6
12
September 6, 2021
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
🌐
GeeksforGeeks
geeksforgeeks.org › java › scanner-class-in-java
Scanner Class in Java - GeeksforGeeks
Explanation: In the above code example, we use the nextLine() of Scanner class to read the line value which is entered by the user and print it in the console. Import the java.util.Scanner package at the beginning of the program. import java.util.Scanner public class Geeks{ public static void main(String [] args){ } } ... Here "sc" is an object of the Scanner class. We can give it different names for our ease such as in, var or obj etc. Using this object we can use the methods of the Scanner class. ... The scanner class helps take the standard input stream in Java.
Published: May 27, 2026
🌐
Medium
medium.com › @bhangalekunal2631996 › different-ways-to-take-input-from-the-user-in-java-b61f55fda0e3
Different ways to take input from the user in Java | by Kunal Bhangale | Medium
April 12, 2024 - In Java programming, capturing user input is a fundamental requirement for creating interactive applications. By leveraging the Scanner class, BufferedReader, or Console class, developers can efficiently handle various input scenarios and create ...
🌐
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 use the Scanner class, which is a component of the java.util package to accept string input from the user. Utilizing the Scanner class is the most commonly used method, but you can also use the BufferedReader class and other methods.
Find elsewhere
🌐
BeginnersBook
beginnersbook.com › 2024 › 06 › how-to-take-string-input-in-java
How to take String Input in Java
June 9, 2024 - import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; public class StringInputExample { public static void main(String[] args) { // Create a BufferedReader object BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); // Prompt user for string input System.out.println("Enter a string:"); try { // Read user input String input = reader.readLine(); // print user entered string System.out.println("You entered: " + input); } catch (IOException e) { e.printStackTrace(); } } }
🌐
DataFlair
data-flair.training › blogs › how-to-take-string-input-in-java
How to Take String Input in Java? - DataFlair
May 30, 2026 - Java provides various classes and methods to facilitate String input. They are as follows: Using BufferedReader class readLine() method. Using Scanner class nextLine() method. Through the Scanner class next() method.
🌐
Scaler
scaler.com › home › topics › string input in java
String Input in Java - Scaler Topics
May 4, 2023 - Java has a various number of I/O Streams that help the user in performing all the input-output activities, taking string input from the user can be done using these I/O streams. Further in this article, we will discuss all those approaches that are needed to be followed for taking string input. The Scanner class is provided by the java.util package and is used to take input from the user.
🌐
DEV Community
dev.to › realedwintorres › tutorial-accepting-string-input-in-java-4j9o
Tutorial: Accepting String Input in Java - DEV Community
October 31, 2021 - Some Java programs need input from the user. To accept input from the user, use the Scanner class. The Scanner class has methods that accept different types of input. This tutorial describes string input.
🌐
JavaBeat
javabeat.net › input-string-java
How to Input a String in Java?
January 31, 2024 - The “String args []” in the main() method are known as default arguments that are used for taking runtime input. Let’s use the Command-line args to take string input by the user.
🌐
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 - So let’s start the tutorial on taking String input in Java. Taking string input in Java means taking the String input from the user through the keyboard and then the input values are processed and we get the desired output of the program.
🌐
Programiz
programiz.com › java-programming › basic-input-output
Java Basic Input and Output | Programiz
March 21, 2024 - Similarly, we can use nextLong(), nextFloat(), nextDouble(), and next() methods to get long, float, double, and string input respectively from the user. Note: We have used the close() method to close the object.
🌐
CodeChef
codechef.com › blogs › java-user-input
How to accept User Input in Java (Examples and Practice)
Learn how to take user inputs in Java with this beginner-friendly guide. Discover string and integer inputs, handling multiple inputs, and practical examples to enhance your Java programming skills
🌐
Scaler
scaler.com › home › topics › java › how to take input in java? (with examples)
How to Take Input in Java? (With examples) - Scaler Topics
February 11, 2022 - User Input refers to the data that ... developer. If you're wondering how to take input in java from user, three classes designed for this: BufferedReader, Scanner, and Console....
🌐
LearnYard
read.learnyard.com › java-fundamentals › user-input-in-java
User Input in Java
November 8, 2024 - But in Java, we can also ask users to input values and then store those values in variables. To do this, we use something called the Scanner class. Let's take a look at an example together. import java.util.Scanner; class Main { public static ...
🌐
Medium
medium.com › @manisha10850 › how-to-take-user-input-in-java-9c127bb25200
How to take user input in java. System.in is used to take input and… | by Manisha Shukla | Medium
June 3, 2025 - This method consumes the newline character and returns the input as a string. Useful when you want to read an entire line of text, such as when reading a sentence or a paragraph. ... The next() method reads the next token (sequence of characters separated by whitespace) until it encounters a space, tab, or newline. It does not consume the newline character; it leaves it in the input buffer.
🌐
Home and Learn
homeandlearn.co.uk › java › user_input.html
java for complete beginners - user input
After you hit the enter key, java will take whatever was typed and store it in the variable name to the left of the equals sign. For us, this was the variable called first_name. The programme then moves on to the next line of code: ... The user input has now finished, and the rest of the programme ...
🌐
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 - There are several methods for this, each designed for different scenarios: 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.