c# 输入年份输出一年的日历
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Day01
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入年份");
int year = int.Parse(Console.ReadLine());
bool Estimate=LeapYear(year);//判断是否闰年
for(int month = 1; month < 13; month++)
{
int j;
Console.WriteLine("______________________________________________________");
Console.WriteLine("\n");
Console.WriteLine("\t\t\t"+ month+"月");
Console.WriteLine("\n");
int day = DayOfMonth(Estimate, month);//判断月份的天数
int blank = GetWeekByDay(year, month, day);//计算空格
Console.Write("日\t一\t二\t三\t四\t五\t六\n");
for ( j = 1; j <= blank; j++)//添加空格
{
Console.Write("\t");
}
for(int i=1;i<=day;i++)
{
int a = 8 - j;
if ((i==a)||(i==(a+7))|| (i == (a + 14)) || (i == (a + 21)) || (i == (a + 28)) || (i == (a + 35)) || (i == day)) Console.Write(i +"\n");
else Console.Write(i + "\t");
}
Console.WriteLine( "\n\n");
}
Console.ReadLine();
}
private static int DayOfMonth(bool Estimate, int month)//判断指定月份的天数
{
int day;
if (Estimate == true)
{
if(month==1||month==3||month==5||month==7||month==8||month==12) day = 31;
else if (month==4||month==6||month==9||month==10||month==11) day=30 ;
else day=29;
}
else
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 12) day = 31;
else if (month == 4 || month == 6 || month == 9 || month == 10 || month == 11) day = 30;
else day = 28;
}
return day;
}
private static bool LeapYear(int year)//判断是否为闰年
{
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
return true;
else
return false;
}
private static int GetWeekByDay(int year, int month, int day)//根据年月日计算星期数
{
DateTime dt = new DateTime(year, month, day);
return (int)dt.DayOfWeek;
}
}
}

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Day01
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入年份");
int year = int.Parse(Console.ReadLine());
bool Estimate=LeapYear(year);//判断是否闰年
for(int month = 1; month < 13; month++)
{
int j;
Console.WriteLine("______________________________________________________");
Console.WriteLine("\n");
Console.WriteLine("\t\t\t"+ month+"月");
Console.WriteLine("\n");
int day = DayOfMonth(Estimate, month);//判断月份的天数
int blank = GetWeekByDay(year, month, day);//计算空格
Console.Write("日\t一\t二\t三\t四\t五\t六\n");
for ( j = 1; j <= blank; j++)//添加空格
{
Console.Write("\t");
}
for(int i=1;i<=day;i++)
{
int a = 8 - j;
if ((i==a)||(i==(a+7))|| (i == (a + 14)) || (i == (a + 21)) || (i == (a + 28)) || (i == (a + 35)) || (i == day)) Console.Write(i +"\n");
else Console.Write(i + "\t");
}
Console.WriteLine( "\n\n");
}
Console.ReadLine();
}
private static int DayOfMonth(bool Estimate, int month)//判断指定月份的天数
{
int day;
if (Estimate == true)
{
if(month==1||month==3||month==5||month==7||month==8||month==12) day = 31;
else if (month==4||month==6||month==9||month==10||month==11) day=30 ;
else day=29;
}
else
{
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 12) day = 31;
else if (month == 4 || month == 6 || month == 9 || month == 10 || month == 11) day = 30;
else day = 28;
}
return day;
}
private static bool LeapYear(int year)//判断是否为闰年
{
if ((year % 400 == 0) || ((year % 4 == 0) && (year % 100 != 0)))
return true;
else
return false;
}
private static int GetWeekByDay(int year, int month, int day)//根据年月日计算星期数
{
DateTime dt = new DateTime(year, month, day);
return (int)dt.DayOfWeek;
}
}
}

...全文
相关推荐
Accp5.0万年历小项目
可以使用控制台输出的特殊字符(如ASCII艺术)来美化界面,使得日历看起来更直观。9. **测试与调试**:开发完成后,需要对各个年份进行详尽的测试,确保日历显示正确,无遗漏或错误。10.
C#输入年月展示 当年该月的日历
C#输入年月展示 当年该月的日历
阳历转换农历 .Net
**编程实现**:在C#中,可以创建一个类,如`LunarConverter`,包含方法如`ToLunarDate`,输入一个`DateTime`对象,返回一个包含农历日期和天干地支的对象。
C#控制台日历 可按自己输入年份 可多次输入
标题中的"C#控制台日历 可按自己输入年份 可多次输入"表明这个项目不仅显示当前日期的月份日历,还能允许用户自定义输入年份,并且可以进行多次输入,展示不同年份的日历。
编写Java程序随机输入日期计算星期几,打印任意一年的日历
"该资源是关于使用Java编程语言来实现计算任意日期的星期几以及打印指定年份的日历的功能。用户需要输入年份和月份,程序会根据输入计算出从1900年1月1日到指定日期的总天数,并基于此计算星期几。此外


