csharp FizzBuzz
/* * Write a program that prints the numbers from 1 to 100. * But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". * For numbers which are multiples of both three and five print "FizzBuzz". */ for (int i = 1; i < 101; i++) { StringBuilder s = new StringBuilder(); if (i % 3 == 0) { s.Append("Fizz"); } if (i % 5 == 0) { s.Append("Buzz"); } if (s.Length > 0) { Console.WriteLine(s.ToString()); } else { Console.WriteLine(i.ToString()); } } Console.Read();
My implementation of FizzBuzz, using StringBuilder for fun.
Updated: Saturday 9th October 2010, 10:58pm
There are 0 comments
Comments are currently closed.