Advertisement
zinch

FizzBuzz

Sep 6th, 2017
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.function.*;
  2.  
  3. public class HelloWorld
  4. {
  5.  
  6.      public static void main(String []args)
  7.      {
  8.         System.out.println("Hello World");
  9.         for (int i = 1; i <= 100; i++)
  10.             System.out.println(fizzbuzz(i));
  11.      }
  12.      
  13.      private static String fizzbuzz(int n)
  14.      {
  15.         Function<Function<String, String>, Function<String, String>> fizz = f ->
  16.              (n % 3 == 0)
  17.                 ? s -> "Fizz" + f.apply("")
  18.                 : f;
  19.        
  20.         Function<Function<String, String>, Function<String, String>> buzz = f ->
  21.              (n % 5 == 0)
  22.                 ? s -> "Buzz" + f.apply("")
  23.                 : f;
  24.                
  25.         return fizz.apply(buzz.apply(Function.identity())).apply(String.valueOf(n));
  26.      }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement