Created
March 26, 2014 20:18
-
-
Save Tok/9792289 to your computer and use it in GitHub Desktop.
Java 8 FizzBuzz One-Liner
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
import java.util.stream.IntStream; | |
public class FizzBuzz { | |
public static void main(final String... args) { | |
//Java 8 FizzBuzz One-Liner | |
IntStream.rangeClosed(1, 100).mapToObj(v -> v % 15 == 0 ? "FizzBuzz" : v % 5 == 0 ? "Buzz" : v % 3 == 0 ? "Fizz" : v).forEach(System.out::println); | |
//Parallel FizzBuzz | |
//IntStream.rangeClosed(1, 100).parallel().mapToObj(v -> v % 15 == 0 ? "FizzBuzz" : v % 5 == 0 ? "Buzz" : v % 3 == 0 ? "Fizz" : v).forEachOrdered(System.out::println); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment