this is my code in which i need generate a random number and store in numb variable and pass it to another thread to get the factorial. Need output like this:
Number : 2 Factorial of 2 : 2 Number : 5 Factorial of 5 : 120
run this for 5 times
public class assignment1 {
public static void main(String args[])
{
static int numb=0;
for(int i=0;i<5;i++)
{
Thread t1 = new Thread()
{
public void run()
{
numb = (int) Math.random() * 10;
System.out.println("Number : "+numb);
}
};
Thread t2 = new Thread()
{
int fact = 1;
public void run()
{
for(int x=1;x<=numb;x++)
{
fact=fact*x;
}
System.out.println("Factorial of "+numb+" is "+fact);
}
};
t1.start();
t2.start();
}
}