import java.util.ArrayList;
public class FizzBuzz{
public static void main(String[] args){
System.out.println(fizzBuzz(15));
}
public ArrayList<String> fizzBuzz(int n) {
ArrayList<String> results = new ArrayList<String>();
for (int i = 1; i <= n; i++) {
if (i % 15 == 0) {
results.add("fizz buzz");
} else if (i % 5 == 0) {
results.add("buzz");
} else if (i % 3 == 0) {
results.add("fizz");
} else {
results.add(String.valueOf(i));
}
}
return results;
}
}
I am trying to print out the FizzBuzz array. however, why I can't call the method below by the name here? could anyone help me out please? Appreciate!