import javax.swing.JOptionPane; // 匯入輸入視窗物件
class Season
{
public static void main(String args[])
{
String input1; // 宣告字串變數 input1
int month; // 宣告整數變數 month
input1 = JOptionPane.showInputDialog(" 輸入判別月份:"); //執行輸入視窗, 輸入月份.
month = Integer.parseInt(input1); // 將輸入字串 input1 轉換為整數 month
if (month >= 2 && month <=4)
{
JOptionPane.showMessageDialog(null," 輸入月份為 " + month + " 月,是春天", "四季分類程式",JOptionPane.PLAIN_MESSAGE);
}
if (month >= 5 && month <=7)
{
JOptionPane.showMessageDialog(null," 輸入月份為 " + month + " 月,是夏天", "四季分類程式",JOptionPane.PLAIN_MESSAGE);
}
if (month >= 8 && month <=10)
{
JOptionPane.showMessageDialog(null," 輸入月份為 " + month + " 月,是秋天", "四季分類程式",JOptionPane.PLAIN_MESSAGE);
}
if (month == 11 || month ==12 || month ==1)
{
JOptionPane.showMessageDialog(null," 輸入月份為 " + month + " 月,是冬天", "四季分類程式",JOptionPane.PLAIN_MESSAGE);
}
System.exit(0); // 結束視窗,返回系統。
}
}
- Jun 05 Fri 2009 17:59
Java-判斷月份-1
close
全站熱搜
留言列表
發表留言