Apart from reading
file, Scanner can also read user input from Console in Java. Just like in
case of reading file, we have provided File as source
for scanning, We need to provide System.in as source
to scan for user input in Console. Once you created and initialized java.util.Scanner, you can
use its various read method to read
input from user. If you want to read String, you can use nextLine(), if you
want to read integer numbers, you can use nextInt().
Subsequently you can use nextFloat() to read float input, nextDouble() to read
double input etc. Scanner class also allows you to define your own pattern and
scan for that.