我编写了一个简单的程序来检查输入是否是字母 O。出于某种原因,即使我键入字母 O,程序也会输出输入不是字母 O。我使用 Eclipse 调试器来确保输入变量实际上等于“O”。
import java.util.Scanner;
public class scannerTest {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Give your input. I will tell you if your input is 'O' or not");
String input = scan.next();
if (input == "O"){
System.out.println("Your input was 'O'");
}
else {
System.out.println("Your input was not 'O'");
}
}
}