本文共 906 字,大约阅读时间需要 3 分钟。
Write a program that outputs the string representation of numbers from 1 to n.
But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.程序中主要使用了
# @param {Integer} n# @return {String[]}def fizz_buzz(n) result = Array.new() for i in 1 .. n if i % 3 == 0 and i % 5==0 then result << "FizzBuzz" else if i % 3 == 0 then result << "Fizz" else if i % 5 == 0 then result << "Buzz" else result << "#{i}" end end end end return resultend
转载地址:http://yennx.baihongyu.com/