标签:输入 name ogr ons line nbsp code stat oid
用中间变量做这个题
1、“请输入年份:”(1-9999)
“请输入月份:”(1-12)
“请输入日期:”(要判断大小月,判断闰年)
判断输入的时间日期是否正确
2、计算输入的时间是当前这一年的第几天
namespace _2017_2_23判断日期格式优化代码 { class Program { static void Main(string[] args) { bool dateISOK = false; bool isRN = false; { int year; int month = 0; int day = 0;int num=0; Console.WriteLine("请输入年份:(1-9999)"); year = Convert.ToInt32(Console.ReadLine()); if (year >= 1 && year <= 9999) { if (year >= 1 && year <= 9999 && year % 4 == 0 && year % 100 != 0 || year % 400 == 0) { isRN = true; } Console.WriteLine("请输入月份:"); month = Convert.ToInt32(Console.ReadLine()); if (month >= 1 && month <= 12) { Console.WriteLine("请输入日期:"); day = Convert.ToInt32(Console.ReadLine()); if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12 && day >= 1 && day<= 31) { Console.WriteLine("您输入的日期格式正确"); dateISOK = true; } else if ((month == 4 || month == 6 || month == 9 || month == 11) && day >= 1 && day <= 30) { Console.WriteLine("您输入的日期格式正确"); dateISOK = true; } else if (isRN==true && month == 2 && day >= 1 && day <= 29) { Console.WriteLine("您输入的日期格式正确"); dateISOK = true; isRN = true; } else if (isRN==false && month == 2 && day >= 1 && day <= 28) { Console.WriteLine("您输入的日期格式正确"); dateISOK = true; } else { Console.WriteLine("您输入的日期格式不对"); } } else { Console.WriteLine("您输入的月份格式错误"); } } else { Console.WriteLine("您输入的年份格式错了"); } if(dateISOK==true&&month==1) { num = day; } if(dateISOK==true&&month==2) { num = 31 + day; } if(dateISOK==true&&month==3&&isRN==true) { num = 31 + 29 + day; } if(dateISOK==true&&month==3&&isRN==false) { num = 31 + 28 + day; } if (dateISOK == true && month == 4 && isRN == true) { num = 31 + 29 +31+ day; } if (dateISOK == true && month == 4 && isRN == false) { num = 31 + 28+31 + day; } if (dateISOK == true && month == 5 && isRN == true) { num = 31 + 29 + 31 +30+ day; } if (dateISOK == true && month ==5 && isRN == false) { num = 31 + 28 + 31 +30+ day; } if (dateISOK == true && month == 6 && isRN == true) { num = 31 + 29 + 31 + 30+31 + day; } if (dateISOK == true && month ==6 && isRN == false) { num = 31 + 28 + 31 + 30+31 + day; } if (dateISOK == true && month == 7 && isRN == true) { num = 31 + 29 + 31 + 30 + 31+30 + day; } if (dateISOK == true && month == 7 && isRN == false) { num = 31 + 28 + 31 + 30 + 31+30 + day; } if (dateISOK == true && month == 8 && isRN == true) { num = 31 + 29 + 31 + 30 + 31 + 30 +31+ day; } if (dateISOK == true && month == 8 && isRN == false) { num = 31 + 28 + 31 + 30 + 31 + 30+31 + day; } if (dateISOK == true && month == 9 && isRN == true) { num = 31 + 29 + 31 + 30 + 31 + 30 + 31+31 + day; } if (dateISOK == true && month ==9&& isRN == false) { num = 31 + 28 + 31 + 30 + 31 + 30 + 31 +31+ day; } if (dateISOK == true && month == 10 && isRN == true) { num = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31+30 + day; } if (dateISOK == true && month == 10 && isRN == false) { num = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31+30 + day; } if (dateISOK == true && month == 11 && isRN == true) { num = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 +31+ day; } if (dateISOK == true && month == 11 && isRN == false) { num = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 +31+ day; } if (dateISOK == true && month == 12 && isRN == true) { num = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 +30+ day; } if (dateISOK == true && month == 12&& isRN == false) { num = 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 +30+ day; }
Console.WriteLine("你输入的日期是当年的第"+num+"天"); Console.ReadLine(); } } } }
标签:输入 name ogr ons line nbsp code stat oid
原文地址:http://www.cnblogs.com/zhengqian/p/6432821.html