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();
- Best exam simulation CIW master-ciw-enterprise-developer download free trial.
- Download free practice test for scbcd SCBCD exam.
- Download free practice test for scdjws SCDJWS exam.
- Become SUN SCJP certified.
- Click here to get free scjp-5-0 SCJP 5/6 exam practice questions.
- Download free practice test for scmad SCMAD exam.
- Download free practice test for scwcd SCWCD exam.
- Become SUN Java 5.0 certified.
- Best exam simulation SUN CX310-056 download free trial.
- Click here to download CX310-065 test study guide and practice question.
- Become SUN SCJP Upgrade certified.