我有这个Java代码,我尝试通过系统输出检查变量是否都很好,但我没有退出while循环,为什么? 我输入alex作为用户名,并输入mihai作为密码,但我并没有退出while循环。 而且我觉得这真的很奇怪,因为一切都还好吧?
boolean isGoodUandP = false;
String username = "";
String password = "";
while (isGoodUandP == false) {
System.out.print("Please enter username: ");
Scanner sUsername = new Scanner(System.in);
username = sUsername.nextLine();
System.out.println("username este " + username);
System.out.print("Please enter password: ");
Scanner sPassword = new Scanner(System.in);
password = sPassword.nextLine();
System.out.println("parola este " + password);
if ((username == "alex") && (password == "mihai")) {
isGoodUandP = true;
System.out.println("Bine ati venit!");
}
}