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,
SpringBoot JpaRepository Database addition, deletion, modification and query mysql Modify primary key Mybatis Mapping file Mapper.xml in # and $ The difference between python obtain excel A column or row of data npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! test_vue_0613@1.0.0 dev: Solutions to errors Linux File name validity detection Determine whether the current object is an array 4 Methods Output string at specified position --PTApytorch of ResNet18( Yes cifar10 The accuracy of data classification is achieved 94%) Digital rolling lottery program