如何识别闰年 [英] How to identify the Leap Year

查看:112
本文介绍了如何识别闰年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好先生/女士,



请帮助如何识别闰年。

Hello Sir/Madam,

Please Help how to identify the Leap Year.

推荐答案

你可以在datetime类中使用build方法。它将返回 true / false

you can use build method in datetime class. it will return a true/false.
DateTime.IsLeapYear(2013)


如果你不想使用 DateTime.IsLeapYear()那么试试看用它:

And if you don't want to use DateTime.IsLeapYear() then have a try with it:
try
{
   Console.Write("Please Enter the Year: ");
   int year = int.Parse(Console.ReadLine());
   
   if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))
   {
      Console.WriteLine("The year {0}, is a Leap Year", year);
   }
   else
   {
      Console.WriteLine("The year {0}, is not a Leap Year", year);
   } 
}
catch (Exception ex)
{
   Console.WriteLine(ex.Message);
}


这篇关于如何识别闰年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆