我是刚入门学java的,对系统类不是很了角,学着写了一个小程序,不知为什么程序不能正常结束,请大家帮忙看看如何解决,谢谢。
import javax.swing.JOptionPane;
import javax.swing.JFrame;
public class Season //一个输入月份,判断出季节的程序
{
public static void main(String[] agrs)
{
  String FirstNum;
int i=0,x=0;
sn:
for(;i<1;)
{
FirstNum= JOptionPane.showInputDialog("请输入一个月份值:");
x=Integer.parseInt(FirstNum);
   if(x>=1&&x<=3)
{
JOptionPane.showMessageDialog(null, "这个月份是春季", "结果", JOptionPane.PLAIN_MESSAGE);
int sel=JOptionPane.showConfirmDialog(new JFrame(),"您还继续吗?", "选择", JOptionPane.YES_NO_OPTION);//选择程序是否继续
if(sel==0)
{
System.out.println(sel);
    continue;
  }
 if(sel==1)
{
System.out.println(sel);
    break;
  }

}
else if(x>=4&&x<=6)
{
JOptionPane.showMessageDialog(null, "这个月份是夏季", "结果", JOptionPane.PLAIN_MESSAGE);
int sel=JOptionPane.showConfirmDialog(new JFrame(),"您还继续吗?", "选择", JOptionPane.YES_NO_OPTION);//选择程序是否继续
if(sel==0)
{
System.out.println(sel);
    continue;
  }
 if(sel==1)
{
System.out.println(sel);
    break;
  }
}
else if(x>=7&&x<=9)
{
JOptionPane.showMessageDialog(null, "这个月份是秋季", "结果", JOptionPane.PLAIN_MESSAGE);
int sel=JOptionPane.showConfirmDialog(new JFrame(),"您还继续吗?", "选择", JOptionPane.YES_NO_OPTION);//选择程序是否继续
if(sel==0)
{
System.out.println(sel);
    continue;
  }
 if(sel==1)
{
System.out.println(sel);
    break;
  }
}
else if(x>=10&&x<=12)
{
JOptionPane.showMessageDialog(null, "这个月份是冬季", "结果", JOptionPane.PLAIN_MESSAGE);
  int sel=JOptionPane.showConfirmDialog(new JFrame(),"您还继续吗?", "选择", JOptionPane.YES_NO_OPTION);//选择程序是否继续
if(sel==0)
{
System.out.println(sel);
    continue;
  }
 if(sel==1)
{
System.out.println(sel);
    break;
  }
}
else
{
JOptionPane.showMessageDialog(null, "您输入的不是一个月份!!", "警告", JOptionPane.ERROR_MESSAGE);
int sel=JOptionPane.showConfirmDialog(new JFrame(),"您还继续吗?", "选择", JOptionPane.YES_NO_OPTION);//选择程序是否继续
if(sel==0)
{
System.out.println(sel);
    continue;
  }
 if(sel==1)
{
System.out.println(sel);
    break;
  }
}
}System.out.println("程序结束");
}
}

解决方案 »

  1.   

    在System.out.println("程序结束"); 后边加上
    System.exit(0);
    程序就能退出结束了.
      

  2.   

    if(sel==0) 

    System.out.println(sel); //为了让自己能明白sel的实际值而加入,对于整个程序是没有意义的
            continue; 
        } 
      if(sel==1) 

    System.out.println(sel); //为了让自己能明白sel的实际值而加入,对于整个程序是没有意义的
            break; 
        }