Last active
December 22, 2015 00:39
-
-
Save jon-ruckwood/6391051 to your computer and use it in GitHub Desktop.
Naïve Java 8 FizzBuzz implementation
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(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