Created
May 25, 2014 06:39
-
-
Save koduki/52b41e5ed3d63dcd3997 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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