作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
我在 Java 类(class)上学习了 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 ");
}
}
}
我是一名优秀的程序员,十分优秀!