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

How to use 'scanner' in JAVA?
Number which the user will enter will be stored in getal. You know how to print the value of a variable. More on reddit.com
🌐 r/learnprogramming
3
0
September 18, 2022
Why do we need Scanner class in order to input something?
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 - best also formatted as code block 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. 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/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) 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/learnjava
8
9
July 11, 2022
Fundamentally misunderstanding Java Scanner class.
It seems the consensus is that each program only requires a single Scanner object. There is no such consensus. If you need to read from multiple sources you can and should use several scanners. Secondly, what actually does the close() method of Scanner do? It does whatever it needs to do to properly close the underlying source. It can be a bunch of different things or nothing at all. In the case of a file, it signals the OS that you are done reading so it can free any resource associated with the file. For something like a network connection it might be more complicated. Is the file actually being "opened" somewhere? Yes, files are opened. Scanner probably opens it when it is created. Opening a file tells the OS that you are gonna read (or write) from said file, so it can do the necessary work to make the data available to you. Can Scanners be "re-opened"? I don't believe so, once closed it is basically useless. should you just be closing Scanners (particularly, Scanners with files) and the end of each program? The OS will close any file your program has opened when it is closed. So you don't need to close every scanner. It is good practice to do so tho, since some things do not like to be abruptly closed by the OS (files are fine). And lastly, what's even the purpose of the Scanner class at all? Why do we need a class at all to get input? Does Java not have a Console.ReadLine() equivalent that we can just set to a String variable? Scanner is a convenience class to help read text input from different sources. If you only ever read string from the console you don't need it, but many program do more than that. More on reddit.com
🌐 r/AskProgramming
10
6
April 29, 2021
A small rant regarding the Scanner class...
You rarely see Scanner used anywhere else but with tutorials and class projects. Maybe if you're building a cli tool, but otherwise it's rarely used, which is probably why you probably won't find a huge amount of info online about it's usage. I'm guessing you've read through the JavaDocs for the Class? More on reddit.com
🌐 r/learnjava
22
29
May 14, 2022
People also ask

Q1. What is the Scanner class in Java?
The Scanner class is a utility in Java that helps programs read input from the user, files, or strings.
🌐
intellipaat.com
intellipaat.com › home › blog › scanner class in java
Scanner Class in Java: Syntax, Methods, and Examples
Q5. What is the use of a Scanner?
The Scanner is used to take input from the user and make it easy to read and process numbers, text, or other data types in a program.
🌐
intellipaat.com
intellipaat.com › home › blog › scanner class in java
Scanner Class in Java: Syntax, Methods, and Examples
Q3. How to write a Scanner class?
You create a Scanner object in your program using: Scanner sc = new Scanner(System.in);
🌐
intellipaat.com
intellipaat.com › home › blog › scanner class in java
Scanner Class in Java: Syntax, Methods, and Examples
🌐
Zero To Mastery
zerotomastery.io › blog › java-scanner
Beginner's Guide To Java Scanner (With Code Examples) | Zero To Mastery
Super simple to fix. Just always remember to include this line at the top of your Java file: ... This tells Java where to find the Scanner class so your program can use it.
🌐
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, ... To use the Java Scanner for user input, either import the java.util package, or use the full package and class name, java.util.Scanner....
Published: May 15, 2026
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Scanner.html
Scanner (Java Platform SE 8 )
July 21, 2026 - Finds and returns the next complete token from this scanner. A complete token is preceded and followed by input that matches the delimiter pattern. This method may block while waiting for input to scan, even if a previous invocation of hasNext() returned true.
🌐
Reddit
reddit.com › r/learnprogramming › how to use 'scanner' in java?
r/learnprogramming on Reddit: How to use 'scanner' in JAVA?
September 18, 2022 -

I have to learn how to code in JAVA for school, I have been trying for many hours now but I fail to understand how to to use 'Scanner'

Could anybody help me out with this code to at least teach me how I can use it right the next time? Because the answers to my mistakes is nowhere to be found even after watching countless of Youtube videos.

I have to change the code so that the number will get printed.

Sample input1: 12 > The sample output for this has to be also: 12

Sample input 2: 42 > The sample output for this also has to be: 42

Sample imput 3: -12 > The sample output for this also has to be: -12

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

Scanner scanner = New Scanner(System.in);

int getal = scanner.nextInt();

System.out.println(........)

And then I honestly have no clue what to do..

Please help and thank you in advance

Find elsewhere
🌐
Programiz
programiz.com › java-programming › scanner
Java Scanner Class | Programiz
March 13, 2024 - The Scanner class provides various methods that allow us to read inputs of different types. import java.util.Scanner; class Main { public static void main(String[] args) { // creates a Scanner object Scanner input = new Scanner(System.in); ...
🌐
Baeldung
baeldung.com › home › java › java io › java scanner
Java Scanner | Baeldung
January 5, 2024 - Now – let’s see how to validate input using a Scanner. In the following example – we use the Scanner method hasNextInt() to check if the input is an integer value:
🌐
DigitalOcean
digitalocean.com › community › tutorials › scanner-class-in-java
Scanner Class in Java | DigitalOcean
August 4, 2022 - Technical tutorials, Q&A, events — This is an inclusive place where developers can find or lend support and discover new ways to contribute to the community.
🌐
Quora
quora.com › How-do-I-use-the-scanner-class-in-Java-to-take-a-whole-sentence-as-user-input
How to use the scanner class in Java to take a whole sentence as user input - Quora
Answer (1 of 7): [code]import java.util.Scanner; class Stdin_and_Stdout { public static void main(String[] args) { Scanner s=new Scanner(system.in); int i=s.nextInt(); double d=s.nextDouble(); s.nextLine(); //this is to clear the keyboard buffer String l=s.nextLine(); s.close(); System.out.printl...
🌐
SoftTeco
softteco.com › home › java development › java scanner
Java Scanner: everything you need to know about this Java clas
June 9, 2026 - To use the Scanner class, you’ll need to create a class object and select one of the methods described in the Scanner class documentation. To get the instance of Java Scanner that reads user input, you’ll have to pass the input stream ...
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › Java-String-input-with-the-Scanner-class
Java Scanner String input example
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
🌐
Career Karma
careerkarma.com › blog › java › java user input and scanner class: a step-by-step guide
Java User Input and Scanner Class: A Step-By-Step Guide | Career Karma
December 1, 2023 - Scanner is the primary method of collecting Java user input. After you import the Java Scanner class, you can start to use it to collect user input.
🌐
OneCompiler
onecompiler.com › java › 3va985n6a
scanner - Java - OneCompiler
OneCompiler's Java online editor supports stdin and users can give inputs to the programs using the STDIN textbox under the I/O tab. Using Scanner class in Java program, you can read the inputs.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › io › scanning.html
Scanning (The Java™ Tutorials > Essential Java Classes > Basic I/O)
To use a different token separator, invoke useDelimiter(), specifying a regular expression. For example, suppose you wanted the token separator to be a comma, optionally followed by white space. You would invoke, ... The ScanXan example treats all input tokens as simple String values. Scanner also supports tokens for all of the Java language's primitive types (except for char), as well as BigInteger and BigDecimal.
🌐
CodeRabbit
coderabbit.ai
CodeRabbit | Governance & Control for Agentic Development
Brings in context from PRDs, issues, and internal docs relevant to the work. ... Uses agentic code generation and exploration, static verification, and analysis to deliver a review.
🌐
EC-Council
eccouncil.org › homepage › cybersecurity exchange › ethical hacking › top ethical hacking tools used by ethical hackers in 2026: an expert guide for pentesters, ethical hackers and security professionals
List of Top Ethical hacking tools | Best hacking tools for Cybersecurity professionals
July 28, 2026 - ffuf is a web fuzzing tool used to discover hidden directories, files, parameters, and endpoints within web applications. ... Nikto is a web server vulnerability scanner used to identify outdated software, dangerous files, and security misconfigurations.
🌐
Codebind
codebind.com › home › java – scanner class and getting user input using java
Java – Scanner class and Getting User Input using Java
August 6, 2016 - It also can be used for powerful pattern matching – we will not cover pattern matching in this class. Scanner is in the Java.util package. So you must: import java.util.Scanner;
🌐
TechGeekBuzz
techgeekbuzz.com › home › blog › java › java scanner
Java Scanner [With Examples] - What is Scanner Class in Java?
Though there are many ways in which Scanner class can be used, including passing a string as Scanner scanner = new Scanner("1 2 3 4 5 6 7 8"); or a file location to read from the file contents, we have shown examples only for how the scanner ...
🌐
Intellipaat
intellipaat.com › home › blog › scanner class in java
Scanner Class in Java: Syntax, Methods, and Examples
September 8, 2026 - You can do this with the import java.util.Scanner;. Step 2: Create a Scanner object After importing, you have to create a Scanner object, which will read input from the user.