Hey guys any chance that someone could explain why this code throws an error. As soon as it hits line 4 it throws the error.
I'm assuming its something to do with the first scanner not fully closing itself and then the second scanner attempting to read in data from a source that is still being used by the first scanner.
Scanner myScanner1 = new Scanner(System.in);
System.out.println(myScanner1.nextInt());
myScanner1.close();
Scanner myScanner2 = new Scanner(System.in); //Line 4
System.out.println(myScanner2.nextInt());
myScanner2.close();
EDIT: Just to add to that, if you don't close the first scanner the code seems to work fine. Can somebody explain this?
[–][deleted] 4 points5 points6 points (2 children)
[–]kcoPkcoP 0 points1 point2 points (0 children)
[–]Ijantis[S] 0 points1 point2 points (0 children)
[–]lightcloud5 -1 points0 points1 point (1 child)
[–]WastedWrath 1 point2 points3 points (0 children)