Created
February 26, 2016 09:37
-
-
Save jforge/0ddf32dad6a40f26ee5f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import java.util.function.Function; | |
| import java.util.stream.IntStream; | |
| public class FizzBuzz { | |
| public static void main(String[] args) { | |
| Function<Integer, Boolean> divisible3 = l -> l % 3 == 0; | |
| Function<Integer, Boolean> divisible5 = l -> l % 5 == 0; | |
| Function<Integer, String> outDivisibleFizz = i -> divisible3.apply(i) ? "Fizz" : ""; | |
| Function<Integer, String> outDivisibleBuzz = i -> divisible5.apply(i) ? "Buzz" : ""; | |
| IntStream.rangeClosed(1, 100).mapToObj(i -> { | |
| return outDivisibleFizz.apply(i) + outDivisibleBuzz.apply(i) + ((!divisible3.apply(i) && !divisible5.apply(i)) ? i : ""); | |
| }).forEach(System.out::println); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment