Problem 6: Fizz Buzz Multithreaded.
Category Medium.
Given a class FizzBuzz, with 4 methods fizz (which print fizz),buzz (which print buzz),fizzBuzz (which print fizzBuzz), and printNumber( print a number).
FizzBuzz will be initialized with an integer n.
All four methods will be called from different threads.
the result of running all four threads.
Should be based on i which is 1 to n;
if i % 3 and i % 5 is 0;
return fizzBuzz
if i % 3 is 0;
return fizz
if i % 5 is 0;
return buzz
else if i % 3 and i % 5 is not 0;
return i
.
This problem as well Javascript is not in the programming language because it's single threaded.
Hence I use python to create another threads when all the threads are started.
When the last thread is started.
Iterate through n.
check the condition and call the appropriate thread or printNumber with i
Top comments (0)