-
-
Save manfre/4502333 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
try | |
{ | |
// This loop would be better broken out as a method that accepts | |
// start, end, and step values to control the loop. That would also | |
// require extra bounds checks for end < start, etc. | |
for (int i = 1; i <= 100; i++) | |
{ | |
// Your check methods could be rewritten using modulos | |
bool fizz = i % 3 == 0; | |
bool buzz = i % 5 == 0; | |
// Print the Fizz Buzz parts without trailing newline | |
if (fizz) | |
Console.Write("Fizz"); | |
if (buzz) | |
Console.Write("Buzz"); | |
// Now add the newline | |
if (fizz || buzz) | |
Console.WriteLine(""); | |
else | |
Console.WriteLine(i); | |
} | |
// You can press Ctrl+F5 to run your program and keep the window | |
// open when execution finishes. Or you can require a key press | |
//Console.ReadKey(); | |
} | |
catch (Exception ex) | |
{ | |
Console.WriteLine("Whoops!"); | |
Console.WriteLine(ex.Message); | |
} | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks! I appreciate the feedback. That's a lot better of a solution than mine. :)