Beruflich Dokumente
Kultur Dokumente
Java
1|P ag e
Five events E1, E2, E3, E4 and E5 are going to be organized for Gravitas in VIT,
registration is open for all B.Tech students. With the total strength of 500 students,
simulate the registration for each event by generating 500 random numbers in the
range of 1 – 5. (1 for event E1, 2 for E2… 5 for E5) and store the values in an
array. Create six threads to equally share the task of counting the number of
registration details for all the events. Use synchronized method or synchronized
block to update the count variables. The main thread should receive the final
registration count for all events and display the list of students who have not
registered in any event.
import java.util.*;
import java.io.*;
Vector vec;
int k, i;
this.k = k;
this.vec = vec;
try {
if (vec.elementAt(i).equals(k)) {
count++;
} catch (Exception e) {
System.out.println(e);
2|P ag e
}
public class H {
votevec.add(rand_int1);
ac.start();
bc.start();
cc.start();
dc.start();
ec.start();
try {
ac.join();
bc.join();
cc.join();
dc.join();
3|P ag e
ec.join();
int av = ac.count;
int bv = bc.count;
int cv = cc.count;
int dv = cc.count;
int ev = cc.count;
int cnt = 0;
if (votevec.elementAt(i).equals(0)) {
cnt++;
4|P ag e
Output Screenshot :-
5|P ag e