大家进来帮个忙,谢谢了。

feifei0707 2008-01-27 10:15:08
我是刚入门学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("程序结束");
}
}
...全文
74 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
feifei0707 2008-01-27
  • 打赏
  • 举报
回复
谢谢你,好人。
feifei0707 2008-01-27
  • 打赏
  • 举报
回复
if(sel==0)
{
System.out.println(sel); //为了让自己能明白sel的实际值而加入,对于整个程序是没有意义的
continue;
}
if(sel==1)
{
System.out.println(sel); //为了让自己能明白sel的实际值而加入,对于整个程序是没有意义的
break;
}
约翰羊 2008-01-27
  • 打赏
  • 举报
回复
在System.out.println("程序结束"); 后边加上
System.exit(0);
程序就能退出结束了.

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧