Fizz Buzz 面试题
在CSDN上看到一篇文章《软件工程师如何笑着活下去》,本来是想看对这个行业的一些评价和信息,不曾检索到关于Fizz Buzz的面试题,上网搜了一下,顿感兴趣。留下此文,以表回忆。
java语言 小白基础写法:
public class FizzBuzz {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) { //for循环遍历1-100的数
if (i % 3 ==0 & i%5 == 0) { //循环出的数字i%3和%5看是否相等,相当输出原有数字+FizzBute。
System.out.println(i+" "+"FizzBute");
}else if(i%3==0) { //循环出的数分别%3,相当输出 i+Fizz.
System.out.println(i+" "+"Fizz");
}else if(i%5==0) { //循环出的数分别%5,相当输出 i+Bute.
System.out.println(i+" "+"Bute");
}
else if(i%10==3) {
System.out.println(i+" f"); //个位数不包含,十位数包含3的输出原数字 +f
}
else {
System.out.println(i); //输出原有循环的数字以便容易辨认。
}
}
}
}
Fizz Buzz 面试题的更多相关文章
- [LeetCode] Fizz Buzz 嘶嘶嗡嗡
Write a program that outputs the string representation of numbers from 1 to n. But for multiples of ...
- Lintcode 9.Fizz Buzz 问题
------------------------ AC代码: class Solution { /** * param n: As description. * return: A list of s ...
- LeetCode 412. Fizz Buzz
Problem: Write a program that outputs the string representation of numbers from 1 to n. But for mult ...
- LeetCode Fizz Buzz
原题链接在这里:https://leetcode.com/problems/fizz-buzz/ 题目: Write a program that outputs the string represe ...
- Fizz Buzz
class Solution { public: /** * param n: As description. * return: A list of strings. */ vector<st ...
- LintCode (9)Fizz Buzz
下面是AC代码,C++风格: class Solution { public: vector<string> fizzBuzz(int N) { vector<string> ...
- [重构到模式-Chain of Responsibility Pattern]把Fizz Buzz招式重构到责任链模式
写一段程序从1打印到100,但是遇到3的倍数时打印Fizz,遇到5的倍数时打印Buzz,遇到即是3的倍数同时也是5的倍数时打印FizzBuzz.例如: 1 2 Fizz 4 Buzz Fizz 7 8 ...
- Swift完成fizz buzz test
看到一篇文章上说,很多貌似看过很多本编程书的童鞋连简单的fizz buzz测试都完不成. 不知道fizz buzz test为何物的,建议自行搜之. 测试要求是,编写满足以下条件的代码: Write ...
- [Swift]LeetCode412. Fizz Buzz
Write a program that outputs the string representation of numbers from 1 to n. But for multiples of ...
随机推荐
- Git 简单入门(一)
Git 简介 Git 是目前世界上最先进的分布式版本控制系统 分布式和集中式 集中式版本控制系统 版本库放在中央服务器,干活之前先从中央服务器取得最新版本,然后开始干活,活干完后将自己干的成果推送给中 ...
- Unity进阶----AssetBundle_02(加载依赖关系及网络资源)(2018/10/31)
网络资源加载: string path ="file://"+ Application.streamingAssetsPath + "\\windows\\123&quo ...
- 电子产品使用感受之——为什么我把Apple Watch S2 升级到了 S4?
2019.03.14 更新 最近在手表上安装了“摩拜单车”的APP,这绝对是一款使用体验加分的APP. 我每天上下班都要骑摩拜单车,但是每次掏出手机,首先FACE ID解锁屏幕,然后从上往下滑屏幕来触 ...
- json和pickle模块
import pickleimport json data = {'k1': 123, 'k2': 'Hello'}print(type(data))# p_str = pickle.dumps(da ...
- spring 相关注解详情(一)
1.@controller 控制器(注入服务) 用于标注控制层,相当于struts中的action层2.@service 服务(注入dao) 用于标注服务层,主要用来进行业务的逻辑处理3.@repos ...
- ES6的字符串和数值的扩展
字符串扩展 对于处理大于两个字节(大于0xffff)的字符,let str =’\u{20bb7}abc’ ES5中的遍历 for(let i=0;i<str.length;i++){ con ...
- sql相同表不同查询条件合并显示
关键字:FULL JOIN 只要其中某个表存在匹配,FULL JOIN 关键字就会返回行. select a.createtime, ISNULL(lp, 0) lp , ISNULL(hp, 0) ...
- ESP8266 RTOS SDK烧写环境构建
简介 esptool是一个Python软件程序,适用于ESP8266等一系列芯片的烧写,灵活高效. 环境构建 在官网下载安装最新2.7版python (linux和os x一般会自带python2.7 ...
- OO第一单元总结(表达式求导)
写在前边:第一次接触面向对象语言,编程思想仍然不可避免的有以前面向过程的影子.从第一次作业的完全面向过程,到第二次学会剥离各个类互不影响到第三次作业的先构思面向对象的基本程序架构再编程.虽然程序有些地 ...
- Lintcode: Nuts & Bolts Problem
Given a set of n nuts of different sizes and n bolts of different sizes. There is a one-one mapping ...