Skip to content

Commit a94bc31

Browse files
committedOct 16, 2024
Added String Problem-Solution
Co-authored-by: Ashish Kumar Singh ‹ashishk.singh1008@gmail.com› Co-authored-by: Laxman Singh Koranga <laxmankoranga03@gmail.com>
1 parent 164a647 commit a94bc31

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
 

‎Java/String/FizzBuzz.java

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

0 commit comments

Comments
 (0)