Skip to content

Instantly share code, notes, and snippets.

@jon-ruckwood
Last active December 22, 2015 00: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 jon-ruckwood/6391051 to your computer and use it in GitHub Desktop.
Save jon-ruckwood/6391051 to your computer and use it in GitHub Desktop.
Naïve Java 8 FizzBuzz implementation
import java.util.stream.IntStream;
public class FizzBuzz {
public static void main(String[] args) {
IntStream.range(1, 100).mapToObj(num -> {
final StringBuilder sb = new StringBuilder(8);
if (num % 3 == 0) {
sb.append("Fizz");
}
if (num % 5 == 0) {
sb.append("Buzz");
}
if (sb.length() == 0) {
sb.append(num);
}
return sb.toString();
}).forEach(System.out::println);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment