HW 6.1
package com.gmail.vhrushyn;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread [] threadArray = new Thread[100];
for (int i = 0; i < threadArray.length; i++) {
threadArray[i] = new Thread (new Factorial(i));
threadArray[i].start();
}
System.out.println(Thread.currentThread().getName());
}
}
package com.gmail.vhrushyn;
import java.math.BigInteger;
public class Factorial implements Runnable {
private int n;
@Override
public void run() {
Thread t = Thread.currentThread();
System.out.println(t.getName() + "-> " + n + "!=" + factorialCalculate());
}
public Factorial() {
super();
// TODO Auto-generated constructor stub
}
public Factorial(int n) {
super();
this.n = n;
}
public int getN() {
return n;
}
public void setN(int n) {
this.n = n;
}
private BigInteger factorialCalculate() {
BigInteger fact = new BigInteger("1");
for (int i = 1; i <= this.n; i++) {
fact = fact.multiply(new BigInteger("" + i));
}
return fact;
}
}