Skip to content

Instantly share code, notes, and snippets.

@hasefumi23
Last active March 19, 2019 09:39
Show Gist options
  • Select an option

  • Save hasefumi23/bf134a201c08b48467ee15cb93dbfb9b to your computer and use it in GitHub Desktop.

Select an option

Save hasefumi23/bf134a201c08b48467ee15cb93dbfb9b to your computer and use it in GitHub Desktop.
Java8版のFizzBuzz。
public class FizzBuzz {
public static void main(String[] args) {
IntStream.rangeClosed(1, 100).mapToObj(n ->
(n % 15 == 0) ? "FizzBuzz" :
(n % 3 == 0) ? "Fizz" :
(n % 5 == 0) ? "Buzz" :
String.valueOf(n))
.collect(Collectors.toList()).forEach(System.out::println);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment