Write a program , Output from 1 reach n String representation of numbers .

1. If  n  yes 3 Multiple of , output “Fizz”;

2. If  n  yes 5 Multiple of , output “Buzz”;

3. If  n  At the same time 3 and 5 Multiple of , output “FizzBuzz”.

Examples :

n = 15,

return :
[
    "1",
    "2",
    "Fizz",
    "4",
    "Buzz",
    "Fizz",
    "7",
    "8",
    "Fizz",
    "Buzz",
    "11",
    "Fizz",
    "13",
    "14",
    "FizzBuzz"
]

 

solution :
func fizzBuzz(_ n: Int) -> [String] { guard n > 0 else { return [""] } var
array = [String]() for item in 1...n { if item % 3 == 0 && item % 5 == 0 {
array.append("FizzBuzz") }else if item % 5 == 0{ array.append("Buzz") }else if
item % 3 == 0{ array.append("Fizz") }else{ array.append(String(item)) } }
return array }
 

Technology
©2019-2020 Toolsou All rights reserved,
java Four functional interfaces ( a key , simple ) It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) Browser kernel ( understand )HashMap Explain in detail Some East 14 Pay change 16 salary , Sincerity or routine ?html Writing about cherry trees , Writing about cherry trees