Everyone know factorial right. I m practicing Thread and class relationship. My question is getting results from thread class. If you suggest callbacks, Can you implement callback class for this example.
public class factorial extends Thread {
int sz = 0;
List < String > ar = new ArrayList < String > ();
public factorial(int n) {
this.sz = n;
}
public void run() {
int p = 1;
for (int i = 1; i <= sz; i++) {
p *= i;
ar.add(p + "");
}
}
}
public class Test {
public static List < String > ans = new ArrayList < String > ();
public static void main(String[] args) {
factorial f1 = new factorial(10);
factorial f2 = new factorial(8);
}
}
f1.start()should start the thread storing the incremental factorial values in the listar. Not sure if i am getting your question.