Showing posts with label multiple threading in java. Show all posts
Showing posts with label multiple threading in java. Show all posts

Friday, 13 March 2015

Count factorial using multiple theading

class CountFact implements Runnable{

public void run(){

    try{

        for(int i=1;i<=10;i++)
        {
            int factValue=1;
            Thread.sleep(500);
   
            for(int n=1;n<=i;n++)
            factValue*=n;
       
        System.out.println("factorial of:"+i+"is"+factValue);
        }
    }


    catch(InterruptedException e)
    {

    System.out.println(e);
    }

}

}

class ThreadDemo1
{

    public static void main(String[] args)
    {


        Thread4 t1=new Thread4();
        Thread t3=new Thread(t1);
        t3.start();
    }

}