Skip to content

Instantly share code, notes, and snippets.

@koduki
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koduki/998edee7a06eb26b51f8 to your computer and use it in GitHub Desktop.
Save koduki/998edee7a06eb26b51f8 to your computer and use it in GitHub Desktop.
public static void useList() {
List<String> result = fizzbuzz();
for (String x : result) {
System.out.println(x);
}
}
public static List<String> fizzbuzz() {
List<String> result = new ArrayList<>();
for (int i = 1; i < 100; i++) {
if (i % 15 == 0) {
result.add("FizzBuzz");
} else if (i % 3 == 0) {
result.add("Fizz");
} else if (i % 5 == 0) {
result.add("Buzz");
} else {
result.add(String.valueOf(i));
}
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment