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.
Discussions

In java, how would one scan user input to make sure the input had a "@" in it using a string or a if else statement?
With Java, when you want to see if a value is inside of an object/container there is usually a built-in contains method. I would start by googling to see if the String class has one and how it works More on reddit.com
🌐 r/learnprogramming
5
2
April 24, 2021
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
How do I get user input without using a scanner
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. 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
12
0
August 26, 2024
(JAVA) Use for loop to get user input and keep prompting for input if the wrong number was entered.
I am new to java and trying to get this loop to keep asking the user for input if the wrong one is entered. ... Use for loop to get user input and keep prompting for input if the wrong number was entered. ... Use for loop to get user input and keep prompting for input if the wrong number was entered. ... It's Printing 0. Instead ... More on reddit.com
🌐 r/learnprogramming
2
1
June 29, 2022
People also ask

How much does a Java developer make?
The average Java developer salary in India is INR 4,97,611/year. As an entry-level Java developer, the numbers could vary. The salary of a Java developer also fluctuates based on their experience. The more they experience, the more they get paid. A developer is mainly focused on creating web applications that are then sold in the market. They are a part of a software development team aiming to design, maintain, write, and implement code. Having a bachelor’s in IT or computer science can help you kickstart your journey as a Java professional.
🌐
upgrad.com
upgrad.com › home › blog › software development › how to get user input in java [with examples]
How to get User Input In Java [With Examples] | upGrad blog
How can we take input from the user?
We can take input from users using the Scanner class and BufferedReader class.
🌐
upgrad.com
upgrad.com › home › tutorials › software & tech › how to take input from user in java
How To Take Input From User In Java | upGrad Tutorials
Why should you learn Java?
Java is a user-friendly language and ideal for students learning any programming language. As a language, Java helps you get down on the coding ground and find your way in the infinite software world. Additionally, Java is very versatile and flexible. Java is compatible with any operating system. Due to the pandemic, people have started using their personal devices like laptops, desktops, etc., for work. Java language is designed to work on any OS such as Mac, Windows, iOS, and Android. Moreover, in the future, Java will continue to be in demand. Mobile app downloads in 2020 have increased to
🌐
upgrad.com
upgrad.com › home › blog › software development › how to get user input in java [with examples]
How to get User Input In Java [With Examples] | upGrad blog
🌐
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 - By leveraging the Scanner class, BufferedReader, or Console class, developers can efficiently handle various input scenarios and create user-friendly experiences. Each method has its strengths and use cases, so it’s essential to choose the ...
🌐
Sentry
sentry.io › sentry answers › java › how to get user input in java
Java Get User Input from Console | Sentry
September 3, 2026 - The most common way to get user input in Java is to use the Scanner class from the java.util package.
🌐
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
🌐
javaspring
javaspring.net › blog › how-to-take-user-input-in-java
How to Take User Input in Java — javaspring.net
Taking user input in Java involves reading data from standard input (System.in), which is connected to the keyboard by default. Because System.in is a raw byte stream (InputStream), Java provides higher-level classes in java.util and java.io ...
Find elsewhere
🌐
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 - We need to import multiple libraries into our program to take input through the BufferedReader class. This is the most widely used method for taking inputs in a java program. It uses the Scanner class, which provides us with specific methods to parse the input given to the program using specific ...
🌐
Upgrad
upgrad.com › home › blog › software development › how to get user input in java [with examples]
How to get User Input In Java [With Examples] | upGrad blog
August 11, 2026 - The Java program collects input from the user through various input sources such as a mouse, keyboard, network request, CLI arguments, etc. Java also has various I/O packages that can be imported into the program to perform input-output operations.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › how to take input from user in java
How To Take Input From User In Java | upGrad Tutorials
June 17, 2026 - The Scanner class in Java might just be the most popular method that answers the question: “How to take input from user in Java”. It provides a convenient way to read input from various sources, such as the user's keyboard or file.
🌐
Programiz
programiz.com › java-programming › basic-input-output
Java Basic Input and Output | Programiz
March 21, 2024 - In this tutorial, you will learn simple ways to display output to users and take input from users in Java. We will use the print() method to display output and the Scanner class to take input.
🌐
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.
🌐
Home and Learn
homeandlearn.co.uk › java › user_input.html
java for complete beginners - user input
One of the strengths of Java is the huge libraries of code available to you. This is code that has been written to do specific jobs. All you need to do is to reference which library you want to use, and then call a method into action. One really useful class that handles input from a user is ...
🌐
Programiz PRO
programiz.pro › discuss › java › how-to-accept-user-input-in-java
How to accept user input in Java?
You take user input by creating an object of the Scanner class, and then using the object to call the appropriate method, such as nextInt() for integers, nextDouble() for floating-point numbers, and nextLine() for strings.
🌐
Tutorialspoint
tutorialspoint.com › java › java_user_input.htm
Java - User Input
Java Vs. C++ ... To take input from the user in Java, the Scanner class is used.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-to-take-array-input-from-user-in-java
How to Take Array Input From User in Java? - GeeksforGeeks
July 23, 2025 - We can use the BufferedReader and InputStreamReader classes to read user input in Java and use the IOException class to handle exceptions in input.
🌐
Smartprogramming
smartprogramming.in › tutorials › java › get-user-input-java
How to Get User Input in Java
Below is the program demonstrates ... UserInputExample { public static void main(String[] args) { // Step 1: Create Scanner object Scanner scanner = new Scanner(System.in); // Step 2: Prompt the user for input System.out.print("Enter your name: "); String name = scanner.nextLine(); ...
🌐
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 - In Java Scanner class is used to take input which is part of java.util package. ... We import the Scanner class. We create a Scanner object named scanner that reads input from the standard input stream (System.in).
🌐
Intellipaat
intellipaat.com › home › blog › java user input – scanner, bufferedreader and console
Java User Input - Scanner, BufferedReader and Console - Intellipaat Blog
August 5, 2026 - The Console class is used for secure input, such as passwords. The most common way to take the user input in Java is by using the Scanner class, which is found in the java.util package.