The guy stayed quiet like a robot without uttering a word, smells toxicity. Anyway, here you go.
Posting the question here:
Problem Statement
You need to print numbers in a sequence starting from 0 up to n.
The sequence should look like:
0, 1, 2, 3, 4, ... , n
The input will be a number n, and the program should print all numbers from 0 to n in order.
Thread Requirements
There will be three threads responsible for printing the numbers:
Zero Thread
Responsible for printing 0.
The number 0 should be printed only once.
Odd Thread
Responsible for printing odd numbers: 1, 3, 5, 7, ...
Even Thread
Responsible for printing even numbers: 2, 4, 6, 8, ...
Output Requirement
Along with each number, the output must also indicate which thread printed the number.
Example output format:
0 printed by ZeroThread
1 printed by OddThread
2 printed by EvenThread
3 printed by OddThread
4 printed by EvenThread
...
n printed by respective thread
Design Constraints
There are some mandatory design considerations:
You must implement three separate thread classes:
ZeroThread
OddThread
EvenThread
The business logic for printing numbers must remain inside the respective thread classes:
Logic for printing 0 should be inside the ZeroThread class.
Logic for printing odd numbers should be inside the OddThread class.
Logic for printing even numbers should be inside the EvenThread class.
The numbers must be printed strictly in sequence.
The number 0 should appear exactly once in the output.
Final Expected Behavior
Given an input n, the output should be:
0 printed by ZeroThread
1 printed by OddThread
2 printed by EvenThread
3 printed by OddThread
4 printed by EvenThread
...
n printed by the appropriate thread based on whether the number is odd or even.
=====