码迷,mamicode.com
首页 > Windows程序 > 详细

C#的第一个应用

时间:2017-04-23 15:03:24      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:pac   ***   for   ++   break   oss   system   cti   region   

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
while (true)
{
{
List<string> str = new List<string>();
int year, month;
#region 获取正确的年份
while (true)
{
Console.WriteLine("请输入正确的年份(1900-2100):");
year = int.Parse(Console.ReadLine());
if (year < 1900 || year > 2100)
Console.WriteLine("输入错误,请重新输入年份");
else
{
while (true)
{
Console.WriteLine("请输入月份(1-12):");
month = int.Parse(Console.ReadLine());
if (month < 1 || month > 12)
Console.WriteLine("输入错误,请输入正确的月份");
else
{
break;
}

}
break;
}
Console.ReadLine();
Console.Clear();

}
#endregion
#region 计算到那年年的天数
int dayofyear, crossyear = 0;
for (int i = 1900; i < year; i++)
{
if (i % 4 == 0 && i % 100 != 0 || i % 400 == 0)
dayofyear = 366;
else
dayofyear = 365;
crossyear += dayofyear;

}
#endregion
#region 到那月的天数
int dayofmonth, crossmonth = 0;
for (int i = 1; i < month; i++)
{
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
if (i == 2)
dayofmonth = 29;
else if (i < 8 && i % 2 != 0 || i >= 8 && i % 2 == 0)
dayofmonth = 31;
else
dayofmonth = 30;
}
else
{
if (i == 2)
dayofmonth = 28;
else if (i < 8 && i % 2 != 0 || i >= 8 && i % 2 == 0)
dayofmonth = 31;
else
dayofmonth = 30;
}
crossmonth += dayofmonth;
}
#endregion
#region 计算空格
int week, space;
week = (crossyear + crossmonth) % 7 + 1;
space = week - 1;
for (int i = 0; i < space; i++)
str.Add("");
#endregion
#region 添加台历
int day;
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
{
if (month == 2)
day = 29;
else if (month < 8 && month % 2 != 0 || month >= 8 && month % 2 == 0)
day = 31;
else
day = 30;
}
else
{
if (month == 2)
day = 28;
else if ((month < 8 && month % 2 != 0) || (month >= 8 && month % 2 == 0))
day = 31;
else
day = 30;
}
for (int i = 1; i <= day; i++)
str.Add(i.ToString());
#endregion
#region 输出台历
Console.WriteLine("******************************************************");
Console.WriteLine("一\t二\t三\t四\t五\t六\t日");
for (int i = 0; i < str.Count; i++)
{
if (i % 7 == 0 && i != 0)
Console.WriteLine();

Console.Write(str[i] + "\t");
}
Console.WriteLine();
Console.WriteLine("******************************************************");
#endregion
}
Console.WriteLine("程序结束,请按确认键结束");
Console.ReadLine();
Console.Clear();

}
}
}
}

 

C#的第一个应用

标签:pac   ***   for   ++   break   oss   system   cti   region   

原文地址:http://www.cnblogs.com/lxsir/p/6752479.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!