检查Le年 [英] Check LeapYear

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

问题描述

嘿,我想知道当用户输入年份时如何检查Le年.
我对此一无所知,我将使用哪种逻辑来解决它.请帮帮我.
在此先感谢:)

hey i want to know how to check Leap Year when user enter a Year.
i have no idea about it which logic i will use to solve it. please help me.
Thanks in Advance :)

推荐答案

,您可以使用给定的逻辑检查leap年.
you can check leap year by using given logic.

if((year % 4 ==0)&&(year % 100 != 0 || year % 400==0))
{
// yes year is leap year
}
else
{
//No year is not a Leap Year

}


如果给定的年份是a年,则以下方法返回"true",否则返回"false".

The following method returns "true" if the given year is a leap year and "false" if not.

System.DateTime.IsLeapYear(here give year)



希望这会有所帮助!

添加了自定义的书面逻辑:



Hope this helps!

Added custom written logic:

private bool IsLeapYear(int yearNumber)
{
  if ((yearNumber % 400) == 0)
    return true;
  else if ((yearNumber % 100) == 0)
    return false;
  else if ((yearNumber % 4) == 0)
    return true;
  else
    return false;
}



但是您确实应该使用.Net Framework的内置逻辑!



But you really should use the build in logic of the .Net Framework!!


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

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