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

  1. Write a Java program which has THREE(3) threads.

    1. The first thread will calculate the average value of odd numbers between X and Y (excluding X and Y).
    2. The second thread will calculate the average value of even numbers between X and Y (excluding X and Y).
    3. 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.
    4. If the result is an integer number, display the result using 8-digit binary number.
  2. 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!