Java implementation of Scanner close method
In the following program, a Scanner object closed and once it closed a System stream cannot be re-opened. Hence, after entered string, the control directly printed the default value of int n=0.
KW.java
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW ——————————————————————————————————————————— Java implementation of Scanner close method ——————————————————————————————————————————— Enter the string KODINGWINDOW String KODINGWINDOW Enter the number Number 0 ——————————————————————————————————————————— kodingwindow@kw:~$
Example 2: Java implementation of Scanner close method
KW.java
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Hello, World! Scanner closed kodingwindow@kw:~$
What Next?
Java implementation of a call by value
Implementation of Java method chaining
Java program to print the current date and time
Advertisement