gpt4 book ai didi

java - If 语句在 7 小时内出现问题 JAVA 闰年

转载 作者:行者123 更新时间:2023-12-02 01:00:58 28 4
gpt4 key购买 nike

<分区>

我在 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 ");
}
}
}

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com