Using Scanner.next() to get text input
问题 I am trying to get text input from the keyboard in Java 6. I am new to the language and whenever i run the following code, I get this error: package test1; import java.util.Scanner; public class Test { public static void main(String[] args) { boolean quit = false; while (!quit){ Scanner keyIn; String c = "x"; while (c != "y" && c != "n") { keyIn = new Scanner(System.in); c = keyIn.next(); keyIn.close(); } if (c == "n") quit = true; } } } Exception in thread "main" java.util