Complete Guide For User Input in Java

By | June 7, 2016

How To Take User Input in Java with Scanner Class

Learn How to take User Input in Java Programming Language. To take Input from the User in Java, you can use either the Scanner class or the BufferedReader class. The Scanner class is a newer and an advanced class with a completely new set of methods than the BufferedReader class. The following guide explains How to Input a String, Integer, Float and Double variables in Java from the User.

Also Read: Java Native Interface Step – By – Step Tutorial with C Programming

About Scanner Class

Scanner is a class available in java.util package. The Scanner class reads formatted input from the user and then converts it into Binary format. The Scanner class is used to read any and every type of value from the user including String, Integers, Floats, Double. The Scanner class is a simple text scanner that parses primitive types and strings using regular expressions.

Scanner Class Declaration

To use the Scanner class in a Java program, you have to import the package in your java program file in the following way. The first import statement includes only the Scanner Class from java.util package. If you want to fetch all the classes from the package, you should use the second method.



Scanner Class needs to be instantiated in order to take Input from the User. The Scanner class can be instantiated in the following way:

The is used to get the Input from the User through the Keyboard. This method needs to be used in the Scanner Object’s Constructor.


Also Read: Java Graphics Program To Draw A Circle

Java Program To Read User Input using Scanner Class

Also Read: Java Program To Find Public IP Address


Java Program To Take User Input with Scanner Class

If you have any compilation errors or doubts in this Java Program To Take User Input with Scanner Class, let us know about in the Comment Section below.

Let's Discuss