Writing FizzBuzz

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

    Did anyone do this one already?

    Enumerable.Range(1, 100).Select(x =>
                    (x % 15 == 0) ? "FIZZBUZZ"
                    : (x % 5 == 0) ? "BUZZ"
                    : (x % 3 == 0) ? "FIZZ"
                    : x.ToString()
                    )
                    .ToList()
                    .ForEach(console.WriteLine);
    

提交回复
热议问题