C#判断闰年

Console.WriteLine("请输入要判断的年份");
int year = Convert.ToInt32(Console.ReadLine());
//年份能够被400整除。(2000)
//年份能被4整除,但是不能被100整除。(2008)

//逻辑与的优先级高于逻辑或,最好关系运算式加括号便于阅读

bool result = (year % 400 == 0) || (year % 4 == 0 && year % 100 != 0);

Console.WriteLine(result);
Console.ReadKey();

posted @ 2021-01-10 21:42  默默依然  阅读(1516)  评论(0编辑  收藏  举报