🌐
W3Schools
w3schools.com › java › java_user_input.asp
Java User Input (Scanner class)
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Practice Problems Java Server Java Syllabus Java Study Plan Java Interview Q&A ... 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
The scanner class helps take the standard input stream in Java. So, we need some methods to extract data from the stream. The methods used for extracting data are mentioned below: Let us look at the code snippet to read data of various data types. Example 1: Java program to read data of various types using Scanner class
Published: May 27, 2026
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
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
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
🌐
Baeldung
baeldung.com › home › java › java io › java scanner
Java Scanner | Baeldung
January 5, 2024 - In this quick tutorial, we’ll illustrate how to use the Java Scanner class – to read input and find and skip patterns with different delimiters. First – let’s see how to read a file using Scanner. In the following example – we read a file containing “Hello world” into tokens:
🌐
Programiz
programiz.com › java-programming › scanner
Java Scanner (With Examples)
March 13, 2024 - The Scanner class of the java.util package is used to read input data from different sources like input streams, users, files, etc. In this tutorial, we will learn about the Java Scanner and its methods with the help of examples.
🌐
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
The following Scanner example takes a String of comma-separated values (CSVs) and prints them out one at a time. The program passes the text String to the Scanner’s Java constructor, and then changes the delimiter to a comma.
Published: May 15, 2026
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Scanner.html
Scanner (Java Platform SE 8 )
July 21, 2026 - Java™ Platform Standard Ed. 8 ... A simple text scanner which can parse primitive types and strings using regular expressions. A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different ...
🌐
Zero To Mastery
zerotomastery.io › blog › java-scanner
Beginner's Guide To Java Scanner (With Code Examples) | Zero To Mastery
Declaring a Scanner variable without initializing it will cause a compilation error when you try to use it. This is because Java requires local variables to be assigned a value before they're accessed.
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java › util › scanner
java.util.Scanner – Scanner Java Example (with video)
July 6, 2022 - The scanner can also use delimiters other than whitespace. This example reads several items in from a string: The following code shows you how you can use the Java Scanner class to read a Java input form the console. To start, you create a Scanner object passing System.in (which is the keyboard) as a parameter to the Constructor.
Find elsewhere
🌐
CodeJava
codejava.net › java-se › file-io › java-scanner-tutorial-and-code-examples
Java Scanner Tutorial and Code Examples
July 29, 2019 - Scanner(File source, String charsetName): constructs a Scanner to scan the specified file using the specified character set.
🌐
Oracle
docs.oracle.com › javase › tutorial › essential › io › scanning.html
Scanning (The Java™ Tutorials > Essential Java Classes > Basic I/O)
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. Also, numeric values can use thousands separators.
🌐
TutorialsPoint
tutorialspoint.com › java › util › java_util_scanner.htm
Scanner Class in Java
Below is an example of how to input a number using the Scanner class in Java −
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › util › Scanner.html
Scanner (Java Platform SE 7 )
Java™ Platform Standard Ed. 7 ... A simple text scanner which can parse primitive types and strings using regular expressions. A Scanner breaks its input into tokens using a delimiter pattern, which by default matches whitespace. The resulting tokens may then be converted into values of different ...
🌐
Software Testing Help
softwaretestinghelp.com › home › java › java scanner class tutorial with examples
Java Scanner Class Tutorial With Examples
April 1, 2025 - The output of the program shows ... name; int myclass; float percentage; //creating object of Scanner class Scanner input = new Scanner(System.in); System.out.print("Enter your name: "); name = input.next(); System.out.print("Enter ...
🌐
BeginnersBook
beginnersbook.com › 2022 › 08 › java-scanner-class-with-examples
Java Scanner class with examples
September 11, 2022 - We are using the nextInt() method twice to get two numbers from user and then we are printing the sum of entered numbers. import java.util.Scanner; public class JavaExample { public static void main(String[] args) { // creating a scanner Scanner scan = new Scanner(System.in); System.out.print("Ente
🌐
Scaler
scaler.com › home › topics › scanner class in java
Scanner Class in Java (With Examples) - Scaler Topics
April 3, 2024 - System is a class in Java and in is a static variable of type InputStream. System.in represents the standard input stream. Here is the code snippet for the same: Here, the variable input represents the Scanner class object. While initializing the object input, we are passing the System.in object, which represents the standard input stream. You can use this Scanner object to call various functions the Scanner class provides. ... In the above example, you are taking input from the user through the input stream, but if you want to read data or take input from the file, you can pass the object of class “File” to read the input from the file in the Scanner class constructor.
🌐
FavTutor
favtutor.com › blogs › scanner-class-java
Scanner Class in Java (With Examples)
October 25, 2023 - In the above example, we prompt the user to enter an email address. We use the matches() method of the String class and a regular expression pattern to validate if the entered email address matches the expected format.
🌐
Mkyong
mkyong.com › home › java › java scanner examples
Java Scanner examples | mkyong.com
February 1, 2020 - Long live the Scanner class, a few examples for self-reference. ... package com.mkyong.io; import java.util.Scanner; public class JavaScanner1 { public static void main(String[] args) { try (Scanner scanner = new Scanner(System.in)) { System.out.print("Please enter your name: "); String input = scanner.nextLine(); System.out.println("name : " + input); System.out.print("Please enter your age: "); int age = scanner.nextInt(); System.out.println("age : " + age); } } }
🌐
SoftTeco
softteco.com › home › java development › java scanner
Java Scanner: everything you need to know about this Java clas
June 9, 2026 - It helps read the input of primitive types (i.e. int, double, long, short, float, or byte) and is the easiest way to read input in Java. The Java Scanner class provides the following methods to read different primitives types: The following example allows users to read different types of data form the System.in.
🌐
Intellipaat
intellipaat.com › home › blog › scanner class in java
Scanner Class in Java: Syntax, Methods, and Examples
September 8, 2026 - For example, you can tell the Scanner to split input using a comma, semicolon, or any other character. It is very useful when reading structured data like CSV files. We can use BigInteger and BigDecimal with the Scanner class in Java when we ...