I am finding it so hard to just print my fizzBuzz method out without having to make it static.
In the code below when I first tried to print out my fizzBuzz method, System.out.println(fizzBuzz(6,10));
, I got an error and it would not let me do this. I had to make it static and then add Arrays.toString
to my System.out.println();
in order for me to review my answer in the console.
I want to be able to print a non-static method in my main but can not seem to do so.
import java.util.Arrays;
public class test {
public static String[] fizzBuzz(int start, int end) {
String[] numbers = new String[end - start];
for (int i = start; i < end; i++) {
if (i % 15 == 0) {
numbers[i - start] = "FizzBuzz";
} else if (i % 3 == 0) {
numbers[i - start] = "Fizz";
} else if (i % 5 == 0) {
numbers[i - start] = "Buzz";
} else {
numbers[i - start] = String.valueOf(i);
}
}
return numbers;
}
public static void main(String[] args) {
// int start = 6;
// int end = 10;
fizzBuzz(6, 10);
System.out.println(Arrays.toString(fizzBuzz(6, 10)));
}
}