Skip to content

Commit 9907900

Browse files
authored
Create 412. Fizz Buzz.java
1 parent eecbb23 commit 9907900

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

412. Fizz Buzz.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// the classic
2+
public class Solution {
3+
public List<String> fizzBuzz(int n) {
4+
List<String> out = new ArrayList<String>();
5+
6+
for (int i = 1; i <= n; i++) {
7+
if (i % 15 == 0) {
8+
out.add("FizzBuzz");
9+
} else if (i % 3 == 0) {
10+
out.add("Fizz");
11+
} else if (i % 5 == 0) {
12+
out.add("Buzz");
13+
} else {
14+
out.add(String.valueOf(i));
15+
}
16+
}
17+
18+
return out;
19+
}
20+
}

0 commit comments

Comments
 (0)