DEV Community

loading...

Discussion on: FizzBuzz challenge in as many languages as possible

Collapse
brianverm profile image
Brian Vermeer 🧑🏼‍🎓🧑🏼‍💻

Language: Java (8 and above)
Code:

    public void fizzBuzz() {
        IntStream.rangeClosed(1,100)
                .mapToObj(this::fizzBuzzer)
                .forEach(System.out::println);
    }

    private String fizzBuzzer(int i){
        if (i % 15 == 0) return "FizzBuzz";
        if (i % 3 == 0) return "Fizz";
        if (i % 5 == 0) return "Buzz";
        return String.valueOf(i);
    }