(2)寫一個程式根據月份來判別季節ex.jan is winter.feb is winer
複製程式
import javax.swing.*;
public class j04254{
public static void main(String[] adsf){
boolean flag = true;
int month=0;
while(flag){
flag = false;
String monthstr = JOptionPane.showInputDialog(null,"請輸入月份1-12");
try {
month = Integer.valueOf(monthstr) ;
} catch (Exception e) {flag = true;}
}
switch (month) {
case 3: case 4: case 5: {
JOptionPane.showMessageDialog(null,month+" 月在春天");
break;
}
case 6: case 7: case 8: {
JOptionPane.showMessageDialog(null,month+" 月在夏天");
break;
}
case 9: case 10: case 11:{
JOptionPane.showMessageDialog(null,month+" 月在秋天");
break;
}
case 12: case 1: case 2:{
JOptionPane.showMessageDialog(null,month+" 月在冬天");
break;
}
default:
JOptionPane.showMessageDialog(null,"您過的可能不是地球的季節吧~");
}
}
}