Path: csiph.com!aioe.org!.POSTED!not-for-mail From: =?UTF-8?Q?Arne_Vajh=c3=b8j?= Newsgroups: comp.lang.java.programmer Subject: Re: So I did "FizzBuzz", in Java! Date: Mon, 18 Jul 2016 19:46:30 -0400 Organization: Aioe.org NNTP Server Lines: 33 Message-ID: References: NNTP-Posting-Host: 7SK6yTFfqwlIPNBLl3l7Qg.user.gioia.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 X-Notice: Filtered by postfilter v. 0.8.2 Xref: csiph.com comp.lang.java.programmer:34964 On 7/18/2016 12:26 PM, Daniel Pitts wrote: > Here's one of my solutions: > > public final class FizzBuzz { > public static void main(final java.lang.String[] args) { > java.util.stream.IntStream > .rangeClosed(1, 100) > .mapToObj(i -> { > final StringBuilder result = new StringBuilder(); > if (0 == i % 3) { > result.append("Fizz"); > } > if (0 == i % 5) { > result.append("Buzz"); > } > if (result.length() == 0) { > result.append(i); > } > > return result; > }).forEachOrdered(System.out::println); > } > } I also think that one would have questionable value in an interview situation. It does show good knowledge of Java especially Java 8. But it is not the simplest and most maintainable approach. Arne