-
FundamentalsNumbersData TypesIntegers
Description Real men use gratuitous switch statements.
Code using System.Linq; public static class Kata { public static string IsOdd(int input) { switch( input.ToString().Last() ) { case '0': case '2': case '4': case '6': case '8': return "Even"; default: return "Odd"; } } }
Preloaded Code using System;
Test Cases namespace Solution { using NUnit.Framework; using System; // TODO: Replace examples and use TDD by writing your own tests [TestFixture] public class SolutionTest { [Test] public void MyTest() { Assert.AreEqual("Odd", Kata.IsOdd(1)); Assert.AreEqual("Even", Kata.IsOdd(2)); Assert.AreEqual("Even", Kata.IsOdd(0)); Assert.AreEqual("Odd", Kata.IsOdd(13)); Assert.AreEqual("Even", Kata.IsOdd(18284)); Assert.AreEqual("Odd", Kata.IsOdd(-17)); } } }
Output:
-
Code - using System.Linq;
- public static class Kata
- {
- public static string IsOdd(int input)
- {
if(input % 2 == 0) return "Even";else return "Odd";- switch( input.ToString().Last() ) {
- case '0':
- case '2':
- case '4':
- case '6':
- case '8':
- return "Even";
- default:
- return "Odd";
- }
- }
- }
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 }}
Please sign in or sign up to leave a comment.