When you close scan , you close System.in , and when you try to re-read it, it throws an exception.
Your instructor is right in one aspect, you should clean up resources only when it comes to System.in .
Instead of reopening the stream every time you need input, you can create your Scanner once and just reuse it where you need to enter:
public static void main(String[] args) throws IOException { Scanner scan = new Scanner(System.in); System.out.println(getUserString("Write something:", scan)); System.out.println(getUserString("Write something else:", scan)); } private static String getUserString(String userCommand, Scanner scan) { System.out.println(userCommand); String userinput = scan.nextLine().trim(); if (userinput.isEmpty()) { System.out.println("Invalid choice"); return getUserString(userCommand, scan); } else { return userinput; } }
source share