Enter your E-mail Address below for Free E-mail Alerts right Into your Inbox: -

Sunday

FizzBuzz sample Program in Java 8

public static String fizzBuzzInJava8(int number) 
{
 String result = Optional.of(number) .map(n -> (n % 3 == 0 ? "Fizz" : ""+ (n % 5 == 0 ? "Buzz" : "")) .get();

 return result.isEmpty() ? Integer.toString(number) : result; 
}

No comments:

Post a Comment