Attempting a FizzBuzz recursive solution in Java to return a list of Strings with n iterations. For example, n = 4 should output ["1","2","Fizz", 4]. However, with my current code the output is just ["4"]. Why is my solution not executing the recursive function? Any other critiques are appreciated!
class Solution {
public List<String> fizzBuzz(int n) {
//create variable to return list of strings
List<String> fbList = new ArrayList<String>();
//base case 1
if(n == 0){
fbList.add(Integer.toString(0));
}
//base case 2
else if(n == 1){
fbList.add(Integer.toString(1));
}
//OW take n and begin reducing recursively from, n - 1
else{
if(n % 3 == 0){
fbList.add("Fizz");
}
else if(n % 5 == 0){
fbList.add("Buzz");
}
else if((n % 3 == 0) && (n % 5 == 0)){
fbList.add("FizzBuzz");
}
else{
fbList.add(Integer.toString(n));
}
//recursive function call
fizzBuzz(n - 1);
}
return fbList;
}
}