📄 thenumberofdaysineachmonth.java
字号:
/**
* @(#)TheNumberOfDaysInEachMonth.java
*
*
* @author
* @version 1.00 2009/3/3
*/
//输出指定月的天数
import javax.swing.JOptionPane;
public class TheNumberOfDaysInEachMonth {
/**
* Creates a new instance of <code>TheNumberOfDaysInEachMonth</code>.
*/
public TheNumberOfDaysInEachMonth() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
//Input year
String stringYear=JOptionPane.showInputDialog(null,"Please input a year,for example, 2009",
"Exercise3.5 Input",JOptionPane.QUESTION_MESSAGE);
//Convert striing into int
int intYear=Integer.parseInt(stringYear);
//input month
String stringMonth=JOptionPane.showInputDialog(null,"Please input a month,for example, 8",
"Exercise3.5 Input",JOptionPane.QUESTION_MESSAGE);
//Convert string into int
int intMonth=Integer.parseInt(stringMonth);
switch(intMonth)
{
case (1):case (3):
case (5):case (7):
case (8):case (10):case (12):
JOptionPane.showMessageDialog(null,"There are 31 days in "+intYear+"/"+intMonth+"\n",
"Exercise3.5 Output",JOptionPane.INFORMATION_MESSAGE );
break;
case (4):case (6):
case (9):case (11):
JOptionPane.showMessageDialog(null,"There are 30 days in "+intYear+"/"+intMonth+"\n",
"Exercise3.5 Output",JOptionPane.INFORMATION_MESSAGE);
break;
case (2):JOptionPane.showMessageDialog(null,"There are "+((((intYear%4==0)&&(intYear%100!=0))||(intYear%400==0))?29:28)+" days in "
+intYear+"/"+intMonth+"\n","Exercise3.5 Output",JOptionPane.INFORMATION_MESSAGE);
break;
default:JOptionPane.showMessageDialog(null,"Your input is some wrong.",
"Exercise3.5 Output",JOptionPane.INFORMATION_MESSAGE);
}
return ;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -