【发布时间】:2015-02-22 02:27:45
【问题描述】:
我进入 Java 课程 4 周,经验为 0。 我被要求创建一个程序,该程序要求输入月份的数字表示示例 1 将是一月,也是一年的输入,并让程序输出 显示月份 如何一个月中有很多天和如果是闰年。这是我缩短的许多尝试之一。我做错了什么,它从 1 月开始,输入无关紧要。
package leapmonth;
import javax.swing.JOptionPane;
public class LeapMonth {
public static void main(String[] args) {
int Year;
int MonthNumber;
String MonthString;
JOptionPane.showMessageDialog(null, " HELLO, WELCOME TO LEAPMONTH ");
MonthString = JOptionPane.showInputDialog( " Please enter the numerical respresentation of the month");
MonthNumber = Integer.parseInt(MonthString);
MonthString = JOptionPane.showInputDialog( " Please enter the year");
Year = Integer.parseInt(MonthString);
if( MonthNumber == 1 && Year % 4 == 0 && Year % 100 != 0 || Year % 400 == 0)
{
JOptionPane.showMessageDialog(null,"The month is January. " + "January has 31 days in it" + " and is also a leap year ");
}
else if( MonthNumber == 1 && Year % 4 != 0 && Year % 100 == 0 || Year % 400 != 0)
{
JOptionPane.showMessageDialog(null,"The month is January. " + "January has 31 days in it" + " and it is not a leap year ");
}
else if( MonthNumber == 2 && Year % 4 == 0 && Year % 100 != 0 || Year % 400 ==0)
{
JOptionPane.showMessageDialog(null,"The month is February. " + "February has 29 days in it because this is a leap year ");
}
else if( MonthNumber == 2 && Year % 4 != 0 && Year % 100 == 0 || Year % 400 != 0)
{
JOptionPane.showMessageDialog(null,"The month is February. " + "February has 28 days in it because this is not a leap year ");
}
}
}
【问题讨论】:
标签: java date if-statement monthcalendar