JavaでFizzBuzzをさくっと
Stream APIを使って標準ライブラリだけでぺぺっと書いたらこんな感じになった。
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.stream.IntStream; | |
public class Main { | |
public static void main(String[] args) { | |
IntStream.range(1, 100).boxed() | |
.map(n -> n % 15 == 0 ? "FizzBuzz" | |
: n % 5 == 0 ? "Buzz" | |
: n % 3 == 0 ? "Fizz" | |
: n) | |
.forEach(System.out::println); | |
} | |
} |