Swift完成fizz buzz test

Swift完成fizz buzz test,第1张

概述看到一篇文章上说,很多貌似看过很多本编程书的童鞋连简单的fizz buzz测试都完不成. 不知道fizz buzz test为何物的,建议自行搜之. 测试要求是,编写满足以下条件的代码: Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of

看到一篇文章上说,很多貌似看过很多本编程书的童鞋连简单的fizz buzz测试都完不成.

不知道fizz buzz test为何物的,建议自行搜之.

测试要求是,编写满足以下条件的代码:

Write a program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number which are multiples of both three and five print  “FizzBuzz”.

更通俗的说就是:

For each integer between 1 and 100,inclusive:If the number is divisible by '3',then print "Fizz"If the number is divisible by '5',then print "Buzz"If the number is divisible by both '3' and '5',then print "FizzBuzz"Otherwise,print the number.

本猫用Swift的解决方案如下:

for x in 1...100{    if x % 3 == 0 && x % 5 == 0{        print("FizzBuzz")    }else if x % 3 == 0{        print("Fizz")    }else if x % 5 == 0{        print("Buzz")    }else{        print(x)    }}

好吧,我承认是超级简单…我是有够无聊… ;[

总结

以上是内存溢出为你收集整理的Swift完成fizz buzz test全部内容,希望文章能够帮你解决Swift完成fizz buzz test所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1073321.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存