我們要進(jìn)行判斷
首先要看一年是否是閏年
然后再判斷月份有多少天
這個(gè)代碼
不夠快樂
沒什么樂趣
很難過(guò)
static void Main(string[] args)
{
Console.WriteLine("請(qǐng)輸入一個(gè)年份");
int year = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("請(qǐng)輸入一個(gè)月份");
int month = Convert.ToInt32(Console.ReadLine());
if (month >= 1 && month <= 12)
{
int day = 0;//存儲(chǔ)天數(shù)
switch (month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: day = 31;
break;
case 2:
if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0))
{
day = 29;
}
else
{
day = 28;
}
break;
default: day = 30;
break;
}//swich
Console.WriteLine("{0}年{1}月有{2}天", year, month, day);
Console.ReadKey();
}//if
else
{
Console.WriteLine("月份必須在1~12月之間,程序退出!??!");
}
}