首页 / C# / 2017-2-23 C#基础 中间变量
2017-2-23 C#基础 中间变量
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了2017-2-23 C#基础 中间变量,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4039字,纯文字阅读大概需要6分钟。
内容图文
用中间变量做这个题
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; } elseif ((month == 4 || month == 6 || month == 9 || month == 11) && day >= 1 && day <= 30) { Console.WriteLine("您输入的日期格式正确"); dateISOK = true; } elseif (isRN==true && month == 2 && day >= 1 && day <= 29) { Console.WriteLine("您输入的日期格式正确"); dateISOK = true; isRN = true; } elseif (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(); } } } }
原文:http://www.cnblogs.com/zhengqian/p/6432821.html
内容总结
以上是互联网集市为您收集整理的2017-2-23 C#基础 中间变量全部内容,希望文章能够帮你解决2017-2-23 C#基础 中间变量所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。