-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLucky.java
More file actions
33 lines (32 loc) · 993 Bytes
/
Lucky.java
File metadata and controls
33 lines (32 loc) · 993 Bytes
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
public class Lucky {
static int x = 0;
static int count = 0;
static Integer Count = count;
static class LuckyThread extends Thread {
@Override
public void run() {
synchronized (Count) {
while (x < 999999) {
x++;
if ((x % 10) + (x / 10) % 10 + (x / 100) % 10 == (x / 1000)
% 10 + (x / 10000) % 10 + (x / 100000) % 10) {
System.out.println(x);
Count++;
}
}
}
}
}
public static void main(String[] args) throws InterruptedException {
Thread t1 = new LuckyThread();
Thread t2 = new LuckyThread();
Thread t3 = new LuckyThread();
t1.start();
t2.start();
t3.start();
t1.join();
t2.join();
t3.join();
System.out.println("Total: " + Count);
}
}