Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #34964

Re: So I did "FizzBuzz", in Java!

From Arne Vajhøj <arne@vajhoej.dk>
Newsgroups comp.lang.java.programmer
Subject Re: So I did "FizzBuzz", in Java!
Date 2016-07-18 19:46 -0400
Organization Aioe.org NNTP Server
Message-ID <nmjpok$1e1d$2@gioia.aioe.org> (permalink)
References <FizzBuzz-20160717163715@ram.dialup.fu-berlin.de> <nmj00i$jae$1@dont-email.me>

Show all headers | View raw


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

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: So I did "FizzBuzz", in Java! Daniel Pitts <usenet@coloraura.com> - 2016-07-18 09:26 -0700
  Re: So I did "FizzBuzz", in Java! Eric Douglas <e.d.programmer@gmail.com> - 2016-07-18 10:10 -0700
    Re: So I did "FizzBuzz", in Java! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-18 14:09 -0400
      Re: So I did "FizzBuzz", in Java! Eric Douglas <e.d.programmer@gmail.com> - 2016-07-18 14:00 -0700
        Re: So I did "FizzBuzz", in Java! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-18 17:30 -0400
          Re: So I did "FizzBuzz", in Java! Eric Douglas <e.d.programmer@gmail.com> - 2016-07-19 05:06 -0700
            Re: So I did "FizzBuzz", in Java! Eric Sosman <esosman@comcast-dot-net.invalid> - 2016-07-19 08:13 -0400
              Re: So I did "FizzBuzz", in Java! Eric Douglas <e.d.programmer@gmail.com> - 2016-07-19 05:18 -0700
        Re: So I did "FizzBuzz", in Java! Martin Gregorie <martin@address-in-sig.invalid> - 2016-07-18 21:59 +0000
        Re: So I did "FizzBuzz", in Java! Arne Vajhøj <arne@vajhoej.dk> - 2016-07-18 19:51 -0400
  Re: So I did "FizzBuzz", in Java! Arne Vajhøj <arne@vajhoej.dk> - 2016-07-18 19:46 -0400

csiph-web