How to get input from user in java
This program tells you how to get input from user in a java program. We are using Scanner class to get input from user. This program firstly asks the user to enter a string and then the string is printed, then an integer and entered integer is also printed and finally a float and it is also printed on the screen. Scanner class is present in java.util package so we import this package in our program. We first create an object of Scanner class and then we use the methods of Scanner class. Consider the statement
Here Scanner is the class name, a is the name of object, new keyword is used to allocate the memory and System.in is the input stream. Following methods of Scanner class are used in the program below :-- nextInt to input an integer
- nextFloat to input a float
- nextLine to input a string
Java programming source code
Download User input program class file.
Output of program:
There are other classes which can be used for getting input from user and you can also take input from other devices.
ConversionConversion EmoticonEmoticon