gpt4 book ai didi

C# - 编写一个显示日历的程序,只询问年份和月份,使用 System.DateTime

转载 作者:行者123 更新时间:2023-12-04 17:55:07 24 4
gpt4 key购买 nike

<分区>

我坚持这个,我需要帮助我如何要求用户输入输入任何年份和任何月份,然后将输出指定年份和月份的月历,我还需要使用 system.datetime这是我到目前为止的代码,我认为它不正确,我们将不胜感激。谢谢

class Program
{
static int year = new int();
static int month = new int();
static int[,] calendar = new int[6, 7];

static void Main(string[] args)
{
Console.Write("Enter the year? ");
year = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter the month (January = 1, etc): ");
month = Convert.ToInt32(Console.ReadLine());

DrawHeader();
FillCalendar();
DrawCalendar();
Console.ReadLine();
}

static void DrawHeader()
{
Console.Write("\n\n");
Console.WriteLine("\t" + month);
Console.WriteLine("Mo Tu We Th Fr Sa Su");
}

static void FillCalendar()
{
int days = DateTime.DaysInMonth(year, month);
int currentDay = 1;
for (int i = 0; i < calendar.GetLength(0); i++)
{
for (int j = 0; j < calendar.GetLength(1) && currentDay <= days; j++)
{
if (i == 0 && month > j)
{
calendar[i, j] = 0;
}
else
{
calendar[i, j] = currentDay;
currentDay++;
}
}
}
}

static void DrawCalendar()
{
for (int i = 0; i < calendar.GetLength(0); i++)
{
for (int j = 0; j < calendar.GetLength(1); j++)
{
if (calendar[i, j] > 0)
{
if (calendar[i, j] < 10)
{
Console.Write(" " + calendar[i, j] + " ");
}
else
{
Console.Write(calendar[i, j] + " ");
}
}
else
{
Console.Write(" ");
}
}
Console.WriteLine("");
}
}
}

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