Topic: java选择结构无法实现

  Print this page

1.java选择结构无法实现 Copy to clipboard
Posted by: advancing
Posted on: 2009-11-05 21:53

private void JComboBoxMonthItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:

leap=YEAR%4==0&&YEAR%100!=0||YEAR%400==0;
month=(String)JComboBoxMonth.getSelectedItem();
if(month.startsWith("4")||month.startsWith("6")||month.startsWith("9")||month.startsWith("11"))
{
JComboBoxDay.removeItem("31");
}

else if((!leap)&&month=="2")
{
JComboBoxDay.removeAllItems();

JComboBoxDay.addItem("26");
JComboBoxDay.addItem("27");
JComboBoxDay.addItem("28");
JComboBoxDay.addItem("29");
JComboBoxDay.addItem("30");
JComboBoxDay.addItem("31");
JComboBoxDay.removeItem("31");
JComboBoxDay.removeItem("30");
JComboBoxDay.removeItem("29");
}
else if(month.startsWith("1")||month.startsWith("3")||month.startsWith("5")||month.startsWith("7")||month.startsWith("8")||month.startsWith("10")||month.startsWith("12"))
{
JComboBoxDay.removeAllItems();

JComboBoxDay.addItem("26");
JComboBoxDay.addItem("27");
JComboBoxDay.addItem("28");
JComboBoxDay.addItem("29");
JComboBoxDay.addItem("30");
JComboBoxDay.addItem("31");

}
else if((leap)&&month=="2")
{
JComboBoxDay.removeAllItems();

JComboBoxDay.addItem("26");
JComboBoxDay.addItem("27");
JComboBoxDay.addItem("28");
JComboBoxDay.addItem("29");
JComboBoxDay.addItem("30");
JComboBoxDay.addItem("31");
JComboBoxDay.removeItem("31");
JComboBoxDay.removeItem("30");

}
}

private void JComboBoxYearItemStateChanged(java.awt.event.ItemEvent evt) {
// TODO add your handling code here:
year=(String)JComboBoxYear.getSelectedItem();
YEAR=Integer.parseInt(year);
}

无论YEAR取什么值都执行 else if((leap)&&month=="2")分支
当注释 else if((leap)&&month=="2")分支时执行else if((!leap)&&month=="2")分支


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923