首页 > 其他 > 详细

Leap Years

时间:2015-07-05 21:06:39      阅读:299      评论:0      收藏:0      [点我收藏+]

Description:

In this kata you should simply determine, whether a given year is a leap year or not. In case you don‘t know the rules, here they are:

  • years divisible by 4 are leap years
  • but years divisible by 100 are no leap years
  • but years divisible by 400 are leap years

Additional Notes:

  • Only valid years (positive integers) will be tested, so you don‘t have to validate them

Examples can be found in the test fixture.

using System;

public static class Kata
{
  public static bool IsLeapYear(int year)
  {
    // TODO
    bool flag = false;
            if (year % 4 == 0)
            {
                if (year % 100 == 0)
                {
                    if (year % 400 == 0)
                    {
                        flag = true;
                    }
                }
                else
                {
                    flag = true;
                }
            }
            return flag;
  }
}

 

 

其他人的解法:物体吐槽了,.net自带了相关的函数

using System;

public static class Kata
{
  public static bool IsLeapYear(int year)
  {
          
     return DateTime.IsLeapYear(year);
  }
}

 

Leap Years

原文:http://www.cnblogs.com/chucklu/p/4622911.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!