12345678910111213141516171819202122232425262728293031323334353637 |
- using System;
- static class DataCalculate
- {
- static void Main()
- {
- Console.Write("请输入年份:");
- int year = int.Parse(Console.ReadLine());
- Console.Write("请输入月份:");
- int month = int.Parse(Console.ReadLine());
- Console.Write("请输入日期:");
- int day = int.Parse(Console.ReadLine());
- int daysInYear = GetDaysInYear(year, month, day);
- Console.WriteLine($"{year}年{month}月{day}日是该年的第{daysInYear}天。");
- }
- public static int GetDaysInYear(int year, int month, int day)
- {
- int[] daysInMonths = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
- if (IsLeapYear(year))
- {
- daysInMonths[1] = 29;
- }
- int days = day;
- for (int i = 0; i < month - 1; i++)
- {
- days += daysInMonths[i];
- }
- return days;
- }
- public static bool IsLeapYear(int year)
- {
- return (year % 4 == 0 && year % 100!= 0) || (year % 400 == 0);
- }
- }
|