以下是使用 C# 语言编写的代码:

using System;

class MainClass {
  public static void Main (string[] args) {
    Console.Write('请输入年份:');
    int year = Convert.ToInt32(Console.ReadLine());
    Console.Write('请输入月份:');
    int month = Convert.ToInt32(Console.ReadLine());

    bool isLeapYear = DateTime.IsLeapYear(year);

    Console.WriteLine('{0}年是{1}年。', year, isLeapYear ? '闰' : '平');

    int daysInMonth = DateTime.DaysInMonth(year, month);

    Console.WriteLine('{0}年{1}月有{2}天。', year, month, daysInMonth);
  }
}

运行程序后,用户需要输入年份和月份。程序会根据输入的年份判断该年是否为闰年,并输出相应的信息。然后程序会计算输入的年份和月份有多少天,并输出结果。

C# 代码:判断闰年并计算月份天数

原文地址: http://www.cveoy.top/t/topic/nViT 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录