使用下面的代码,当我使用+,-和Q时,循环不会结束。
String[] validOperators = {"+", "-", "/", "*", "=", "q", "Q"};
String userInput;
Scanner scanner = new Scanner(System.in);
System.out.print("Please enter an operation (+, -, /, *, = or Q to quit): ");
userInput = scanner.nextLine();
while(Arrays.binarySearch(validOperators, userInput) <= -1) {
System.out.print("Invalid input (+, -, /, *, = or Q to quit): ");
userInput = scanner.nextLine();
}
为什么会发生这种情况,我如何以正确的方式实施?
偶然的你
互换的青春
江户川乱折腾
相关分类