嗨,我有一些代码供 Java 控制台在按下特定键时执行某些操作。系统输入密钥并将其存储为字符串,我可以打印出来以确认它是否有效。但是,代码从不进入条件语句,而是每次都跳转到 else。这是代码:
Scanner MenuChoice = new Scanner(System.in);
Products.MenuCode = MenuChoice.next();
if(Products.MenuCode=="F")
{
//Run subprogram for finding a product.
Find.main();
}
else{
System.out.println("F - Find a Product");
System.out.println("p - Purchase a Product");
System.out.println("Q - Quit");
Scanner MenuChoice2 = new Scanner(System.in);
Products.MenuCode = MenuChoice2.next();
};
怎么了?