0
ans = JOptionPane.showInputDialog(null, "Enter amount to be withdrawn from checking");
double withCheck = Double.parseDouble (ans);
if (withCheck >= checking)
    {
    JOptionPane.showMessageDialog(null, "You do not have enough in your account for that.");
    }
else
    {
    double sum = checking - withCheck;
    JOptionPane.showMessageDialog(null, "Your checking balance is now: $" + sum + ", and your savings balance is: $" + savings);
    }
}

目前此代码在 withCheck >= 检查时结束程序,我想知道一种使用某种循环再次询问问题的方法,直到“if”语句为假并且可以继续到 else 语句。

4

1 回答 1

0

只需添加一个条件为true的while 循环,并在某些条件下为真。break

While(true)
{
    ans = JOptionPane.showInputDialog(null, "Enter amount to be withdrawn from checking");
    double withCheck = Double.parseDouble (ans);
    if (withCheck >= checking)
        {
        JOptionPane.showMessageDialog(null, "You do not have enough in your account for that.");
        }
    else
        {
        double sum = checking - withCheck;
        JOptionPane.showMessageDialog(null, "Your checking balance is now: $" + sum + ", and your savings balance is: $" + savings);
        break;
        }
    }
}
于 2013-02-13T20:41:03.537 回答