Ad
Code
Diff
  • import static java.util.stream.IntStream.rangeClosed;
    import java.util.List;
    
    interface FizzBuzz {
      static List<String> evaluate(int input) {
        return rangeClosed(1, input).mapToObj(FizzBuzz::determineFizzbuzz).toList();
      }
      
      private static String determineFizzbuzz(int n) {
        if (n % 15 == 0) return "FizzBuzz";
        if (n % 3 == 0) return "Fizz";
        if (n % 5 == 0) return "Buzz";
        return "" + n;
      }
    }
    • import static java.util.stream.IntStream.rangeClosed;
    • import java.util.List;
    • interface FizzBuzz {
    • static List<String> evaluate(int input) {
    • return rangeClosed(1, input).mapToObj(FizzBuzz::determineFizzbuzz).toList();
    • }
    • private static String determineFizzbuzz(int n) {
    • if(n % 15 == 0) return "FizzBuzz";
    • var ans = new StringBuilder();
    • if (n % 3 == 0) ans.append("Fizz");
    • else
    • if (n % 5 == 0) ans.append("Buzz");
    • return ans.length() > 0 ? ans.toString() : Integer.toString(n);
    • if (n % 15 == 0) return "FizzBuzz";
    • if (n % 3 == 0) return "Fizz";
    • if (n % 5 == 0) return "Buzz";
    • return "" + n;
    • }
    • }