- Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathVITHonors.java
55 lines (43 loc) · 1.16 KB
/
VITHonors.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
importjava.util.Vector;
classAttendance {
staticintwinners = 0;
staticVector<Integer> arr = newVector<>();
staticsynchronizedvoidcounting(intn) {
System.out.println(Thread.currentThread().getName() + " is counting");
for (inti = n - 1000; i < n; i++) {
if (arr.get(i) == 100)
winners++;
}
}
}
classcountextendsThread {
intn;
count(intn) {
this.n = n;
}
publicvoidrun() {
Attendance.counting(n);
}
}
publicclassVITHonors {
publicstaticvoidmain(String[] args) {
intmax = 100;
intmin = 75;
for (inti = 0; i < 2000; i++) {
intn = (int) (Math.random() * ((max - min) + 1) + min);
Attendance.arr.add(n);
}
Threadt1 = newcount(1000);
Threadt2 = newcount(2000);
t1.start();
t2.start();
try {
t1.join();
t2.join();
} catch (InterruptedExceptione) {
System.out.println(e);
}
System.out.println(Attendance.arr);
System.out.println("Winners are = " + Attendance.winners);
}
}