【发布时间】:2016-12-02 00:19:18
【问题描述】:
我需要有关如何根据用户输入显示一个月中的所有星期一日期的指导,可以是任何一天和任何月份。 到目前为止,我的代码在这里,但似乎没有显示日期。我输入的指定日期,哪里出了问题,非常感谢任何帮助。
using System;
using System.Globalization;
namespace Calendar
{
class Program
{
static int promptDay = new int();
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());
Console.Write("Enter the day you want to see the dates for (Mon = 0, etc): ");
promptDay = Convert.ToInt32(Console.ReadLine());
DrawHeader();
FillCalendar();
DrawCalendar();
Console.ReadLine();
}
static void DrawHeader()
{
Console.Write("\n\n");
//gives you the month and year at the top of the calendar
Console.WriteLine(CultureInfo.CurrentCulture.DateTimeFormat.GetMonthName(month) + " " + year);
Console.WriteLine("Mo Tu We Th Fr Sa Su");
}
static void FillCalendar()
{
int currentDay = 1;
for (int i = 0; i < calendar.GetLength(0); i++)
{
for (int j = 0; j < calendar.GetLength(1) && currentDay <= totalDays; j++)
{
if (i == 0 && day > j)
{
calendar[i, j] = 0;
}
else
{
if (j != promptDay)
{
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("");
}
}
}
}
【问题讨论】:
-
你为什么要这样声明你的
ints? -
yh 我试过了,但它不要求用户输入?我怎么能得到那个?
-
我编辑了我之前尝试过的新代码,
-
请检查一下,看看我哪里出错了