标签:
1.输入年份,月份,天,判断这个日期是否正确?
1 static void Main(string[] args) 2 { 3 4 int year, month, day; 5 //输出 6 Console.Write("输入年:"); 7 year = Convert.ToInt32(Console.ReadLine()); 8 9 Console.Write("输入月"); 10 month = Convert.ToInt32(Console.ReadLine()); 11 12 Console.Write("输入天"); 13 day = Convert.ToInt32(Console.ReadLine()); 14 15 16 17 if (year > -9999 && year <= 9999) 18 { 19 //年份对 20 21 22 if (month >= 1 && month <= 12) 23 { 24 //月分对 25 26 if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) 27 { 28 if (day >= 1 && day <= 31) 29 { 30 //天对——都对了。 31 Console.WriteLine("输入正确"); 32 } 33 else 34 { 35 //天错了 36 Console.WriteLine("天输入有错"); 37 } 38 } 39 else if (month == 4 || month == 6 || month == 9 || month == 11) 40 { 41 if (day >= 1 && day <= 30) 42 { 43 //天对——全对 44 Console.WriteLine("输入正确"); 45 } 46 else 47 { 48 //天错了 49 Console.WriteLine("天输入有错"); 50 } 51 } 52 else//2月 53 { 54 //做闰平年判断 55 if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)//闰年 56 { 57 if (day >= 1 && day <= 29) 58 { 59 //天对——全对 60 Console.WriteLine("输入正确"); 61 } 62 else 63 { 64 //天错了 65 Console.WriteLine("天输入有错"); 66 } 67 } 68 else//平年 69 { 70 if (day >= 1 && day <= 28) 71 { 72 //天对了,全对 73 Console.WriteLine("输入正确"); 74 } 75 else 76 { 77 //天错了 78 Console.WriteLine("天输入有错"); 79 } 80 } 81 } 82 83 } 84 else 85 { 86 //月分错 87 Console.WriteLine("月份有错"); 88 } 89 } 90 else 91 { 92 Console.WriteLine("年份错误"); 93 } 94 95 }
2.输入年份,月份显示这个月有多少天?
1 static void Main(string[] args) 2 { 3 Console.Write("请输入年份:"); 4 int year = Convert.ToInt32(Console.ReadLine()); 5 Console.Write("请输入月份:"); 6 int month = Convert.ToInt32(Console.ReadLine()); 7 8 if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) 9 { 10 Console.WriteLine("本月是31天"); 11 } 12 else if (month == 4 || month == 6 || month == 9 || month == 11) 13 { 14 Console.WriteLine("本月是30天"); 15 } 16 else if (month == 2) 17 { 18 if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) 19 { 20 Console.WriteLine("29天"); 21 } 22 else 23 { 24 Console.WriteLine("28天"); 25 } 26 } 27 else 28 { 29 Console.WriteLine("月份有问题"); 30 } 31 }
标签:
原文地址:http://www.cnblogs.com/yuyu1993/p/5392847.html