Scanner is a class present in the java.util package. Like the BufferedReader class, this class is used to take user inputs. However, unlike BufferedReader, which throws checked IOException, it does not throw any checked exception. In addition to taking an input from the user, it is also used to parse through the elements of the code. This class contains the hasNext, hasNextLine, hasNextInt, and hasNextDouble methods to check whether any more element is present. It throws an unchecked InputMismatchException, if the next token is not of the correct type.
Example:
Scanner s= new Scanner(System.in);
String str= s.next();
int nextvalue=s.nextInt();
s.close();
- Download free practice test for CIW Master CIW Enterprise Developer exam.
- Download practice question and study guide for scbcd for exam.
- Click here to get free scdjws SCDJWS exam practice questions.
- Download free practice test for SUN SCJP exam.
- Best exam simulation SUN scjp-5-0 download free trial.
- Become SUN SCMAD certified.
- Best exam simulation SUN scwcd download free trial.
- Get certified in first attempt download CX310-055 - Java 5.0 simulation.
- Pass SCJP 5.0 Java Upgrade in first attampt.
- Get certified in first attempt download CX310-065 - SCJP 6.0 simulation.
- Best exam simulation SUN CX310-066 download free trial.
If you like this article, please leave a comment or subscribe this blog via RSS or via e-mail, Bookmark and share through your network. Click the AddThis button below. Thanks.