Skip to content

Instantly share code, notes, and snippets.

@IngeFrodo
Created August 26, 2020 17:02
Show Gist options
  • Save IngeFrodo/e76ea1a5c16348e3eaccbb249ef1961a to your computer and use it in GitHub Desktop.
Save IngeFrodo/e76ea1a5c16348e3eaccbb249ef1961a to your computer and use it in GitHub Desktop.
class FizzBuzz {
public List<String> fizzBuzz(int n) {
List<String> fizzBuzz = new ArrayList<>();
for (int i = 1; i <= n; i++) {
if (i % 15 == 0) {
fizzBuzz.add("FizzBuzz");
} else if (i % 5 == 0) {
fizzBuzz.add("Buzz");
} else if (i % 3 == 0) {
fizzBuzz.add("Fizz");
} else {
fizzBuzz.add(String.valueOf(i));
}
}
return fizzBuzz;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment