写一个程序,输出从 1 到 n 数字的字符串表示。

1. 如果 n 是3的倍数,输出“Fizz”;

2. 如果 n 是5的倍数,输出“Buzz”;

3.如果 n 同时是3和5的倍数,输出 “FizzBuzz”。

示例:
输入:15
输出:["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz","13","14","FizzBuzz"]
func fizzBuzz(n int) []string { s := []string{} for i:=1; i<=n ;i++{ if i%3 ==0
&& i % 5 == 0 { s = append(s,"FizzBuzz") }else if i%3 ==0 { s =
append(s,"Fizz") }else if i%5 == 0{ s = append(s,"Buzz") }else { s =
append(s,strconv.Itoa(i)) } } return s }
 解题要点:int转string 使用strconve.Itoa(i)函数

技术
©2019-2020 Toolsou All rights reserved,
HashMap详解某东14薪变16薪,是诚意还是套路?浏览器内核(理解)java四大函数式接口(重点,简单)html写樱花树,写樱花树的作文让人意想不到的Python之樱花树(turtle库的华丽样式)os模块的简单使用