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 master-ciw-enterprise-developer Master CIW Enterprise Developer exam.
- Click here to get free scbcd SCBCD exam practice questions.
- Pass SUN scdjws - SCDJWS
- Pass SCJP in first attampt.
- Become SUN SCJP 5/6 certified.
- Become SUN SCMAD certified.
- Click here to download scwcd test study guide and practice question.
- Download free practice test for SUN Java 5.0 exam.
- Get certified in first attempt download CX310-056 - SCJP 5.0 Java Upgrade simulation.
- Become SUN SCJP 6.0 certified.
- Get certified in first attempt download CX310-066 - SCJP Upgrade simulation.