I want to calculate N over K (binominal coefficient) in a thread, which opens then another thread and calculates 1 line of the N over K calculation.
So each thread opens another thread until the N over K is completely done.
Tried now multiple times with loops but doesnt seem to work at all.
Any ideas?
It should be 1 thread which starts another and so on ( so each other inside the one before) until its done.
package Uebung3;
public class Uebung3neu {
static long n =22;
static long q = 3;
public static void main(String[] args) {
RekParNeu x= new RekParNeu(n, q);
x.run();
System.out.println("Fakultät von "+ n+" über " + q+ " = "+x.binom(n, q));
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
package Uebung3;
import java.io.*;
import java.util.concurrent.RecursiveTask;
public class RekParNeu implements Runnable {
public RekParNeu(long n, long q){
run();
}
public synchronized static long binom(long n, long q)
{
if (q==n || q==0)
return 1;
else return binom(n-1,q-1) + binom(n-1, q);
}
public synchronized void run() {
while (Uebung3neu.n!=0&&Uebung3neu.q!=0){
Uebung3neu.n--;
Uebung3neu.q--;
System.out.println("lalalalla");
RekParNeu a= new RekParNeu(Uebung3neu.n,Uebung3neu.q);
a.binom(Uebung3neu.n, Uebung3neu.q);
}
try {
java.lang.Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}