# LeetCode Fizz Buzz题目分析代码

Write a program that outputs the string representation of numbers from 1 to n.

But for multiples of three it should output “Fizz” instead of the number and for the multiples of five output “Buzz”. For numbers which are multiples of both three and five output “FizzBuzz”.

Example:

n = 15,

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

# 题目

• 如果这个数被3整除，打印fizz.
• 如果这个数被5整除，打印buzz.
• 如果这个数能同时被3和5整除，打印fizz buzz.

# 代码

```public class Solution {
public List<String> fizzBuzz(int n) {
List<String> res = new ArrayList<String>();
for(int i=1;i<=n;i++) {
if(i % 15 == 0)
else if(i % 3 == 0)
else if(i % 5 == 0)
else
}
return res;
}
}```

Paste_Image.png

0 条评论

## 相关文章

### HUDOJ-----1394Minimum Inversion Number

Minimum Inversion Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit:...

3686

### 线程池工作窃取实例

ForkJoinPool主要用到的是双端队列，不过这里我们粗糙的实现的话，也可以不用到deque。

2171

1272

1053

### Socket与Http方式解析发送xml消息封装中间件jar包

最近项目代码中太多重复的编写Document,不同的接口需要不同的模板，于是重写提取公共部分打成jar包，方便各个系统统一使用~

1543

3506

3296

### poj 3126 Prime Path

Description ? The ministers of the cabinet were quite upset by the message from ...

2857

1421

### Code forces 719A Vitya in the Countryside

A. Vitya in the Countryside time limit per test:1 second memory limit per test:2...

3496