Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Don't close Scanner when opened to
import java.util.Scanner;
public class ScannerClosePlay {
public static void main(String[] args) {
Scanner scanner1 = new Scanner(;
System.out.print("Enter foo: ");
String foo = scanner1.nextLine();
Scanner scanner2 = new Scanner(;
System.out.print("Enter bar: ");
String bar = scanner2.nextLine(); // Exception
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment