-4 java javafx logical-operators
我的&&逻辑运算符将无法工作,并始终返回false并返回第二个条件为true.但它对||非常有效 运营商.我做错了什么?
我尝试使用|| 运算符,它工作正常,但我想使用&&运算符
@FXML
private void loginFunction() throws IOException {
String username = this.username.getText();
String password = this.username.getText();
if (username.equals("username") && password.equals("password")) {
// This Code is used to alert the user of any information in case the username
// and password is all correct
Alert alert2 = new Alert(Alert.AlertType.CONFIRMATION);
alert2.setHeaderText("Login Successful");
alert2.setTitle("Welcome");
alert2.setContentText("Pleae Wait. You shall be redirected soon.");
alert2.show();
} else {
Alert alert3 = new Alert(Alert.AlertType.WARNING);
alert3.setTitle("Intruder Found");
alert3.setContentText("Either your username or password is incorrect. Please try again.");
alert3.setHeaderText("Enter the Right Details");
alert3.show();
return;
}
}
Run Code Online (Sandbox Code Playgroud)
我希望第一个条件返回为真,但事实并非如此.对于||,情况并非如此 运营商.
好吧
String username = this.username.getText();
String password = this. username.getText();
Run Code Online (Sandbox Code Playgroud)
意味着你的两个领域是相同的.改变它,像,
String username = this.username.getText();
String password = this.password.getText();
Run Code Online (Sandbox Code Playgroud)
因为文本中username不能同时是 "用户名"和"密码".
| 归档时间: |
|
| 查看次数: |
46 次 |
| 最近记录: |