Question: Encounter exception test issues when solving fizzbuzz problem. It is a different version of the original fizzbuzz problem. The inputs are two integers, consider a
Encounter exception test issues when solving fizzbuzz problem.
It is a different version of the original fizzbuzz problem. The inputs are two integers, consider a series of numbers between these two integers (start inclusive, end exclusive). The function will return a new array containing the string from these numbers, except some number are converted to "fizz" "buzz" "fizzbuzz" (as fizzbuzz problem rule). I wrote the following code for solution.
But I cannot pass the following two exception tests:

The error says "Expected :java.lang.IllegalArgumentException. Actual:java.lang.NegativeArraySizeException".
public static String[] getFizzBuzz(int start, int end) { // TODO: Please implement the method // end) throw new IllegalArgumentException(); for(int i = start; i @Test void should_throw_if_inputs_are_negative() { assertThrows (IllegalArgumentException.class, () -> FizzBuzz.getFizzBuzz(-2, -1)); } @Test void should throw_if_start_is_greater_than_end() { assertThrows (IllegalArgumentException.class, () -> FizzBuzz.getFizzBuzz(10, 1)); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts

