Writing FizzBuzz

后端 未结 30 2128
庸人自扰
庸人自扰 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:12

    Not the most efficient, but here's one using C#-6 string interpolation:

    void Main()
    {
        for (int i = 1; i <= 100; i++)
        {
           Console.WriteLine($"{(i % 15 == 0 ? "FizzBuzz" : 
                                 i % 3 == 0 ? "Fizz" : 
                                 i % 5 == 0 ? "Buzz" : i.ToString())}");
        }
    }
    

提交回复
热议问题