JOptionPane,帮助返回

时间:2014-03-14 03:49:20

标签: java string joptionpane parseint

这是我在本网站上的第一篇文章,因为这个网站得到了很多帮助。我想出的不是一个问题,而是我想学习如何做的事情。这是我的代码

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,我将如何将其实现到我的代码中

1 个答案:

答案 0 :(得分: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");
    }
 }
}