Java is not a language with training wheels. It is a language for professional programmers.

— Hebert Sheildt

Reading Input From The Console in Java

I still remember the printf and scanf functions in C language, it is one of the first things that we come across when we learn C language. But when it comes to Java it is a little different, we need to use Scanner class present in the java.util package to read from the console.

While creating an object of the Scanner class, we need to pass an object of However there are various constructors available which also allow you to read from a file.

If we want to read a String value from the console, then have to use the nextLine() method. There are several other methods available, you can check the Java docs of the Scanner class.

© Copyright © 2013 All Rights Reserved.

Free Web Hosting