Hey! it's day 6 of 10 days of coding challenge with I4G. Today's task was to write a code that executes fizz buzz multitreaded output.
Understanding of the problem: The first approach was to understand the task and the constraint attached. Here we writing a code that takes in an integer and prints fizz if the number is divisible by 3, Buzz if the number is divisible by 5, FizzBuzz if the number is divisible by both 3 and 5 or print out the number meets none of the above condition.
Solution: To achieve this, we need another that will be used to iterate through the given integer. For each iteration the conditions above are tested and the function that meet the condition is executed.
- initialize an integer count to 1
- Set a while loop for each function with condition: count < n (the given integer)
- If count is divisible by 3 but not by 5, call the printFizz function
- If count is divisible by 5 but not by 3, call the printBuzz function
- If count is divisible by both 3 and 5 call the printFizzBuzz function
- If count is not divisible by both 3 and 5, call the printNumber function
checkout the code here: https://leetcode.com/problems/fizz-buzz-multithreaded/submissions/
Top comments (0)