using System; namespace ConsoleApp1 { internal class Program { public static void Main(string[] args) { Console.WriteLine("Enter number: "); string userInput = Console.ReadLine(); CheckNumber(userInput); } //CheckNumber() public static void CheckNumber(string stringNumber) { double doubleNumber; bool success = double.TryParse(stringNumber, out doubleNumber); if (success) { switch (doubleNumber % 2) { case 0: Console.WriteLine("Even number"); break; case 1: Console.WriteLine("Odd number"); break; } } else { Console.WriteLine("Invalid Entry"); } } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter