Question: Write a Java program which has THREE(3) threads. The first thread will calculate the average value of odd numbers between X and Y (excluding X
-
Write a Java program which has THREE(3) threads.
- The first thread will calculate the average value of odd numbers between X and Y (excluding X and Y).
- The second thread will calculate the average value of even numbers between X and Y (excluding X and Y).
- The third thread will calculate the average value of prime numbers between X and Y (excluding X and Y). The result MUST be displayed after the first and second threads have completed. Use CyclicBarrier to solve the problem.
- If the result is an integer number, display the result using 8-digit binary number.
-
The values of X and Y MUST be input from the keyboard. The program file and the class name which has the main method MUST be named MyCyclicBarrier.java and place in the src folder.
Example of the output
Enter the X: 1 Enter the X: 12 Odd numbers: 3,5,7,9,11 Even numbers: 2,4,6,8,10 Prime numbers: 2,3,5,7,11 Average value of odd numbers: 00000111 Average value of even numbers: 00000110 Average value of prime numbers: 5.6
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
