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();
- Pass Master CIW Enterprise Developer in first attampt.
- Download practice question and study guide for scbcd for exam.
- Best exam simulation SUN scdjws download free trial.
- Download free practice test for SUN SCJP exam.
- Become SUN SCJP 5/6 certified.
- Pass SCMAD in first attampt.
- Download free practice test for scwcd SCWCD exam.
- Best exam simulation SUN CX310-055 download free trial.
- Become SUN SCJP 5.0 Java Upgrade certified.
- Pass SUN CX310-065 - SCJP 6.0
- Click here to get free CX310-066 SCJP Upgrade exam practice questions.
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.
