-
Code using System; public class LeapYears { public static bool IsLeapYear(int year) { return year % 400 == 0 || year % 100 != 0 && year % 4 == 0; } }
Test Cases namespace Solution { using NUnit.Framework; using System; [TestFixture] public class LeapTests { [Test] public void Test1() { Assert.AreEqual(true, LeapYears.IsLeapYear(2000)); } [Test] public void Test2() { Assert.AreEqual(true, LeapYears.IsLeapYear(2004)); } [Test] public void Test3() { Assert.AreEqual(true, LeapYears.IsLeapYear(2008)); } [Test] public void Test4() { Assert.AreEqual(false, LeapYears.IsLeapYear(1913)); } [Test] public void Test5() { Assert.AreEqual(true, LeapYears.IsLeapYear(1848)); } [Test] public void Test6() { Assert.AreEqual(false, LeapYears.IsLeapYear(2397)); } [Test] public void Test7() { Assert.AreEqual(false, LeapYears.IsLeapYear(1900)); } } }
Output:
-
Code - using System;
- public class LeapYears
- {
- public static bool IsLeapYear(int year)
- {
return year % 4 == 0 && !(year%100==0 && year % 400 != 0);- return year % 400 == 0 || year % 100 != 0 && year % 4 == 0;
- }
- }
- All
- {{group.name}} ({{group.count}})
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}