Writing FizzBuzz

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

    I tried to solve this problem without looking at the answers. It took me 3 hours to succeed. (I'm just a hobby programmer by the way so don't bash me hard please :)) This is my c# version solution:

            static void Main(string[] args)
        {
    
            for (int i = 1; i <= 100; i++)
            {
                if(  ((i % 3) != 0) && ((i % 5) != 0))
                {
                    WriteLine($"{i}");
                }
                else
                {
                    if ((i % 15) == 0)
                    {
                        WriteLine("FizzBuzz");
                    }
                    else if ((i % 3) == 0)
                    {
                        WriteLine("Fizz");
                    }
                    else if ((i % 5) == 0)
                    {
                        WriteLine("Buzz");
                    }
                }                 
            }
        }
    

提交回复
热议问题