小编Kel*_*elv的帖子

count ++不在if语句中工作

尝试显示错误消息,以便当用户输入错误三次时,将显示错误消息"帐户被阻止".为什么每次输入错误的引脚时pinAttempts ++都不会加1?

try {
    int pinAttempts = 0;
    int pin = Integer.parseInt(enterPinJTextField.getText());
    if (pinAttempts == 3) {
        JOptionPane.showMessageDialog(popupFrame, "Account blocked!");
    }
    if (pin != PIN) {
        pinAttempts++;
        JOptionPane.showMessageDialog(popupFrame, "Please enter correct pin!");
    } else {
        BankAccount application = new BankAccount();
        application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
} catch (NumberFormatException exception) {
    JOptionPane.showMessageDialog(popupFrame, "Please enter a number");
}
Run Code Online (Sandbox Code Playgroud)

java

-1
推荐指数
1
解决办法
739
查看次数

标签 统计

java ×1