-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFizz_Buzz_412.java
More file actions
34 lines (30 loc) · 917 Bytes
/
Fizz_Buzz_412.java
File metadata and controls
34 lines (30 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package Daily_Problem;
import java.util.ArrayList;
import java.util.List;
public class Fizz_Buzz_412 {
public static void main(String[] args) {
Solution solution = new Fizz_Buzz_412().new Solution();
List<String> result = solution.fizzBuzz(15);
System.out.println(result);
}
class Solution {
public List<String> fizzBuzz(int n) {
List<String> str=new ArrayList<>();
for(int i=1;i<=n;i++)
{
if(i%3==0 && i%5==0)
str.add("FizzBuzz");
else if(i%3==0)
str.add("Fizz");
else if(i%5==0)
str.add("Buzz");
else
{
String a=String.valueOf(i);
str.add(a);
}
}
return str;
}
}
}