2014-03-14 71 views
0

這是我在這個網站上的第一篇文章,因爲這個網站有很多幫助。我提出的不是一個問題,而是我想學習如何去做的事情。這裏是我的代碼JOptionPane,返回幫助

String a = JOptionPane.showInputDialog(null,"Please pick something for me to do master:\nMynumber,Read2me, Conversions"); 
if (a.equals("Mynumber")) 
{ 
    MyNumber = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter your number: ")); 
    String b = JOptionPane.showInputDialog(null,"Was Your number "+MyNumber+"\n Y/N"); 
    if (b.equals("y")) 
    { 
     JOptionPane.showMessageDialog(null,"Good...good, now lets play with\n your number"); 
    } 
    else if(b.equals("N")) 
    { 
     JOptionPane.showMessageDialog(null,"returning"); 

我的目標是當它到達最後的(當用戶鍵入n)的我想它返回到起始字符串,或字符串A,我將如何實現這個我代碼

回答

0

添加一個循環,你的代碼,例如

while(true) { // instead of while(true) you can also write other condition 
String a = JOptionPane.showInputDialog(null,"Please pick something for me to do master:\nMynumber,Read2me, Conversions"); 
if (a.equals("Mynumber")) { 
    MyNumber = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter your number: ")); 
    String b = JOptionPane.showInputDialog(null,"Was Your number "+MyNumber+"\n Y/N"); 
    if (b.equals("y")) { 
     JOptionPane.showMessageDialog(null,"Good...good, now lets play with\n your number"); 
    } 
    else if(b.equals("N")) { 
     JOptionPane.showMessageDialog(null,"returning"); 
    } 
} 
} 
+0

他還需要一個return語句,並且適當的方法簽名。 –

+0

我將如何返回到代碼的某個部分 –

+0

你究竟想要什麼?在哪裏返回 – Aditya