编写一个程序,提示用户输入一年和一个月的前三个字母名称(第一个字母为大写),并显示该月的天数。 这是一个示例运行:
输入年份:2001年
输入一个月:Jan
“2001年1月有31天”
输入年份:2016年
输入一个月:2月
“2016年1月有29天”(我不明白这一点)我的问题是闰年部分。 我不明白如何使用该程序的其余部分,因为天数应该改变。 我也不明白为什么“2月”的月份在示例中变为“Jan”。 我需要帮助改造我的程序。 我可以使用的是以下代码中所见:“”“如果语句和开关/案例。”“”
import java.util.Scanner;
public class NewClass {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a year: ");
int year = Int();
System.out.print("Enter a month: ");
String month = Line();
// Taken from the book per request of the instructor
boolean isLeapYear = ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
s
本文发布于:2024-01-29 09:27:42,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170649166514312.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |