Skip to content

Instantly share code, notes, and snippets.

@rschoultz
Last active May 4, 2017 16:50
Show Gist options
  • Save rschoultz/2087fd2cc7c1bb5b127469f7dd22c82c to your computer and use it in GitHub Desktop.
Save rschoultz/2087fd2cc7c1bb5b127469f7dd22c82c to your computer and use it in GitHub Desktop.
Another Fizzbuzz, with Java streams. Optimized for brevity.
import java.util.stream.IntStream;
public class FizzBuzz {
public static void main(String[] args) {
IntStream.rangeClosed(1, 100).mapToObj(i -> {
String a;
a = i % 3 == 0 ? "Fizz" : "";
a += i % 5 == 0 ? "Buzz" : "";
return a.isEmpty() ? "" + i : a;
}).forEach(System.out::println);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment