Write a program that outputs the string representation of numbers from 1 to n, however:
For example, for n = 15
, we output: 1, 2, fizz, 4, buzz, fizz,
7, 8, fizz, buzz, 11, fizz, 13, 14, fizzbuzz
.
Suppose you are given the following code:
class FizzBuzz { public FizzBuzz(int n) { ... } // constructor public void fizz(printFizz) { ... } // only output "fizz" public void buzz(printBuzz) { ... } // only output "buzz" public void fizzbuzz(printFizzBuzz) { ... } // only output "fizzbuzz" public void number(printNumber) { ... } // only output the numbers }
Implement a multithreaded version of FizzBuzz
with four
threads. The same instance of FizzBuzz
will be passed to four different
threads:
fizz()
to check for divisibility of 3 and
outputs fizz
.
buzz()
to check for divisibility of 5 and
outputs buzz
.
fizzbuzz()
to check for divisibility of 3 and 5 and
outputs fizzbuzz
.
number()
which should only output the numbers.