Skip to content

Instantly share code, notes, and snippets.

@koduki
Created May 25, 2014 06:39
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/52b41e5ed3d63dcd3997 to your computer and use it in GitHub Desktop.
Save koduki/52b41e5ed3d63dcd3997 to your computer and use it in GitHub Desktop.
public static void useList() {
List<String> result = fizzbuzz(list(1, 100));
for (String x : result) {
System.out.println(x);
}
}
public static List<String> fizzbuzz(List<Integer> source) {
List<String> result = new ArrayList<>();
for (int i : source) {
if (i % 3 == 0 && i % 5 == 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;
}
public static List<Integer> list(int start, int end) {
List<Integer> source = new ArrayList<>();
for (int i = start; i <= end; i++) {
source.add(i);
}
return source;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment