2013-02-13 55 views
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); 
    } 
} 

當前此代碼結束程序whenCheck> =檢查時,我想知道的一種使用方法直到「if」語句爲false並且可以繼續到else語句時,再次詢問該問題的某種循環。我如何emplement循環讓程序再次要求用戶輸入,而不是結束程序

回答

0

它在某些條件得到真正只需添加一個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; 
     } 
    } 
} 
+0

謝謝,我知道這是一個簡單的解決方案,但無法弄清楚。 – JonMichael 2013-02-13 22:00:38

+0

歡迎您:)如果解決了問題,請點擊答案旁邊的勾號,接受答案。 – 2013-02-13 22:04:40

相關問題