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;
}
{
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