#編碼
? ? ? ? ? ?/**
? ? ? ? ? ? *
? ? ? ? ? ? *? 用戶輸年份,再輸入月份,輸出該月的天數(shù)
? ? ? ? ? ? *?
? ? ? ? ? ? * */
? ? ? ? ? ? Console.WriteLine("輸年份");
? ? ? ? ? ? string str_year = Console.ReadLine();
? ? ? ? ? ? int year = Convert.ToInt32(str_year);
? ? ? ? ? ? Console.WriteLine("輸月份");
? ? ? ? ? ? string str_months = Console.ReadLine();
? ? ? ? ? ? int months = Convert.ToInt32(str_months);
? ? ? ? ? ? if (months >= 1 && months <= 12)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? switch(months)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? case 1:
? ? ? ? ? ? ? ? Console.WriteLine("{0}年呵曹,{1}月,有31天",year,months);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 3:
? ? ? ? ? ? ? ? Console.WriteLine("{0}年,{1}月,有31天", year, months);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 4:
? ? ? ? ? ? ? ? Console.WriteLine("{0}年,{1}月,有30天", year, months);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 5:
? ? ? ? ? ? ? ? Console.WriteLine("{0}年,{1}月递礼,有31天", year, months);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 6:
? ? ? ? ? ? ? ? Console.WriteLine("{0}年,{1}月羹幸,有30天", year, months);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 7:
? ? ? ? ? ? ? ? Console.WriteLine("{0}年脊髓,{1}月,有31天", year, months);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 8:
? ? ? ? ? ? ? ? Console.WriteLine("{0}年栅受,{1}月将硝,有31天", year, months);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 9:
? ? ? ? ? ? ? ? Console.WriteLine("{0}年,{1}月屏镊,有30天", year, months);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 10:
? ? ? ? ? ? ? ? Console.WriteLine("{0}年依疼,{1}月,有31天", year, months);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 11:
? ? ? ? ? ? ? ? Console.WriteLine("{0}年而芥,{1}月律罢,有30天", year, months);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? case 2:
? ? ? ? ? ? ? ? if (year % 400 == 0 || (year % 10 == 0 && year % 4 == 0))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.WriteLine("{0}年,{1}月棍丐,有29天", year, months);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? Console.WriteLine("{0}年误辑,{1}月沧踏,有28天", year, months);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ? default:
? ? ? ? ? ? ? ? Console.WriteLine("{0}年,{1}月巾钉,有31天", year, months);
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? else
? ? ? ? ? ? {
? ? ? ? ? ? ? ? Console.WriteLine("月份在1~12之間");
? ? ? ? ? ? }
? ? ? ? ? ? Console.ReadKey();
Console.WriteLine("請輸入一個年份");
int year = Convert.ToInt32(Console.ReadLine());
?????????????????????? Console.WriteLine("請輸入一個月份");
int month = Convert.ToInt32(Console.ReadLine());
if (month >= 1 && month <= 12)
??????????????????? {
int day = 0;//存儲天數(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);
??????????????????? }//if
else
??????????????????? {
Console.WriteLine("月份必須在1~12月之間翘狱,程序退出!>α铡盒蟆!")
#效果
Console.WriteLine("請輸入一個年份");
int year = Convert.ToInt32(Console.ReadLine());
?????????????????????? Console.WriteLine("請輸入一個月份");
int month = Convert.ToInt32(Console.ReadLine());
if (month >= 1 && month <= 12)
??????????????????? {
int day = 0;//存儲天數(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);
??????????????????? }//if
else
??????????????????? {
Console.WriteLine("月份必須在1~12月之間,程序退出Jζ!讨惩!")
Console.WriteLine("請輸入一個年份");
int year = Convert.ToInt32(Console.ReadLine());
?????????????????????? Console.WriteLine("請輸入一個月份");
int month = Convert.ToInt32(Console.ReadLine());
if (month >= 1 && month <= 12)
??????????????????? {
int day = 0;//存儲天數(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);
??????????????????? }//if
else
??????????????????? {
Console.WriteLine("月份必須在1~12月之間辟癌,程序退出!<瞿怼黍少!")