@Test public void fizzFor3() throws Exception { Solution solution = new Solution(); List<String> strings = solution.fizzBuzz(3); assertThat(strings, hasItems("1", "2", "Fizz")); }
public List<String> fizzBuzz(int n) { return IntStream.rangeClosed(1, n).boxed().map(i -> { boolean isFizz = i % 3 == 0; boolean isBuzz = i % 5 == 0; if (isFizz && isBuzz) { return "FizzBuzz"; } else if (isBuzz) { return "Buzz"; } else if (isFizz) { return "Fizz"; } return i.toString(); }).collect(Collectors.toList()); }
Solution { public List<String> fizzBuzz(int n) { return IntStream.rangeClosed(1, n).boxed().map(i -> { boolean isFizz = i % 3 == 0; boolean isBuzz = i % 5 == 0; if (isFizz && isBuzz) { return "FizzBuzz"; } else if (isBuzz) { return "Buzz"; } else if (isFizz) { return "Fizz"; } return i.toString(); }).collect(Collectors.toList()); } }
Solution { public List<String> fizzBuzz(int n) { return IntStream.rangeClosed(1, n).boxed().map(i -> { boolean isFizz = i % 3 == 0; boolean isBuzz = i % 5 == 0; if (isFizz && isBuzz) { return "FizzBuzz"; } else if (isBuzz) { return "Buzz"; } else if (isFizz) { return "Fizz"; } return i.toString(); }).collect(Collectors.toList()); }  }
Solution { public List<String> fizzBuzz(int n) { return IntStream.rangeClosed(1, n).boxed().map(i -> { boolean isFizz = i % 3 == 0; boolean isBuzz = i % 5 == 0; if (isFizz && isBuzz) { return "FizzBuzz"; } else if (isBuzz) { return "Buzz"; } else if (isFizz) { return "Fizz"; } return i.toString(); }).collect(Collectors.toList()); }  List<String> fizzBuzz(int n); }
Solution { public List<String> fizzBuzz(int n) { return IntStream.rangeClosed(1, n).boxed().map(i -> { boolean isFizz = i % 3 == 0; boolean isBuzz = i % 5 == 0; if (isFizz && isBuzz) { return "FizzBuzz"; } else if (isBuzz) { return "Buzz"; } else if (isFizz) { return "Fizz"; } return i.toString(); }).collect(Collectors.toList()); }  List<String> fizzBuzz(int n);  }