Java Scanner close() MethodThe close() is a method of Java Scanner class which is used to closes this scanner. SyntaxFollowing is the declaration of close() method: ParameterThis method does not accept any parameter. ReturnsThe close() method does not return any value. ExceptionsNA Compatibility VersionJava 1.5 and above Example 1Output: Hi All! This is JavaTpoint. Closing Scanner... Scanner Closed. Example 2Output: Enter Your Name: JavaTpoint Name: JavaTpoint Scanner Closed. Example 3Output: Throws Exception If Number is of Type Long. Enter your rollno: 345643985649356 Exception in thread "main" java.util.InputMismatchException: For input string: "345643985649356" at java.base/java.util.Scanner.nextInt(Scanner.java:2264) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at myPackage.ScannerCloseExample3.main(ScannerCloseExample3.java:9) Next TopicJava-scanner-delimiter-method |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India