-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.java
More file actions
43 lines (39 loc) · 1.2 KB
/
Main.java
File metadata and controls
43 lines (39 loc) · 1.2 KB
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
package com.yurii.salimov.lesson06.task07;
import java.math.BigInteger;
/**
* 6.7 Разобраться с методом fact (рекурсия).
*
* @author Yuriy Salimov (yuriy.alex.salimov@gmail.com)
* @version 1.0
*/
public class Main {
public static void main(String[] args) {
try {
final int value = 100;
final int threadsNumber = 3;
final Finish finish = new Finish();
start(value, threadsNumber, finish);
Thread.sleep(1000);
System.out.println(value + "! = " + finish.getResult());
} catch (InterruptedException ex) {
ex.getMessage();
}
}
private static void start(final int arg, final int threadsNumber, final IFinish finish) {
int start = arg;
int end;
for (int i = 0; i < threadsNumber; i++) {
end = start - arg / threadsNumber;
if (end <= 0) {
end = 1;
}
final Task task = new Task(
BigInteger.valueOf(start),
BigInteger.valueOf(end),
finish
);
new Thread(task).start();
start = end - 1;
}
}
}