We haven’t been writing for some time recently coz first I was sick and then The Potato left for her well-deserved vacation.
Now we’re all back to reality so it’s time to get back to programming adventure.
And here’s the task I gave to potato:
Please write a code that will execute game of FizzBuzz
FizzBuzz is a counting game where you change a number into a word as follows:
- Fizz – when the number can be divided by 3
- Buzz – when the number can be divided by 5
- FizzBuzz – when the number can be divided by both: fizz and buzz
For example (starting from 8)
8 Fizz Buzz 11 Fizz 13 14 FizzBuzz
Write a FixxBuzz
Now I’d like you to write a code printing the words for given range of numbers.
- Create a Gradle Project in Eclipse (File > New > Other… > Gradle Project > choose default options)
- Create class and print your FizzBuzz the main method
- Tip: use if-else statement and a loop (for, while or do while)
Take it further
- Create separate a Class FizzBuzz that will have your FizzBuzz code.
- Create method printFromZero() that will print from 0 to the given last number
public void printFromZero(int lastNumber)
- Create method print() that will print your FizzBuzz code for a range of numbers
public void print(int startNumber, int lastNumber)
- Create method fizzOrBuzz() that will return you the text you want to print
public String fizzOrBuzz(int number)