Writing FizzBuzz

后端 未结 30 2143
庸人自扰
庸人自扰 2020-12-04 08:50

Reading the coding horror, I just came across the FizzBuzz another time.

The original post is here: Coding Horror: Why Can\'t Programmers.. Program?

For thos

30条回答
  •  不知归路
    2020-12-04 09:17

    In my opinion, the FizzBuzz problem is always presented as a challenge to the interviwee to make the word FizzBuzz appear without explicitly printing it. Here is my solution in C#.

    internal void PrintFizzBuzzAlternative(int num)
    {
        if (num % 5 == 0)
            Console.Write("Fizz");
        if (num % 3 == 0)
            Console.Write("Buzz");
        if (num % 5 != 0 && num % 3 != 0)
            Console.Write(num);
        Console.WriteLine();
    }
    

提交回复
热议问题