-2

I was instructed to make a FizzBuzz class that has a fizzBuzz method that takes in two int values as parameters. It is not working properly and I am wondering why?

public class FizzBuzz {

public static void main(String[] args) {
    int start = 1;
    int end = 10;
    String[] answers = new String[end +1];
    answers = fizzBuzz(start, end);
    for (String answer : answers) {
            System.out.println(answer);
    }
}

public static String[] fizzBuzz(int start, int end) {
    String[] storage = new String[end + 1];
    for (int i = 1; i < storage.length; i++) {
        for(int j = start; j <= storage.length; j++ ) {
            if (j % (3 * 5)== 0) {
                storage[i] = "fizzbuzz";
            }
            if(j % 5 == 0) {
                storage[i] = "buzz";
            }
            if (j % 3 == 0) {
                storage[i] = "fizz";
            }
            else {
                storage [i] = "" + i;
            }

        }

    }
            return storage;
}

}

ObiJuanKanobe
  • 45
  • 1
  • 6
  • What's the purpose of the nested `for` loops? – Anthony Forloney Apr 02 '16 at 01:12
  • It might help you'd tell us more about the assignment your teacher gave. Especially helpful would be to include what are you supposed to learn by completing this assignment. –  Apr 02 '16 at 01:51
  • I need to get the fizzbuzz method to work correctly and then separate from coding I need to push this to an online repository. – ObiJuanKanobe Apr 02 '16 at 02:36
  • What do you mean by - "not working properly"? Please edit your question and add the output you get and the expected results. – TDG Apr 02 '16 at 07:34

1 Answers1

0

You are missing the elses for the second and third ifs. You are overwriting all fizzbuzzes. There might be other problems, but this is at least a start.