Java using scanner with try-with-resources
I have two versions of Java code that gets user input until user types "q" Version 1: public class Test { public static void main(String[] args) { String input = ""; while (!input.equals("q")) { Scanner scanner = new Scanner(System.in); System.out.print("Input: "); input = scanner.nextLine(); System.out.println("Input was: " + input); } } } Version 2: public class Test { public static void main(String[] args) { String input = ""; while (!input.equals("q")) { try(Scanner scanner = new Scanner(System.in)){ System.out.print("Input: "); input = scanner.nextLine(); System.out.println("Input was: "