class FibbThread implements Runnable
{
Thread t1;
int a=0,b=1,c,no,count;
boolean running = true;
FibbThread(int n)
{
t1=new Thread(this);
t1.start();
no = n;
count = 0;
}
public void run()
{
try
{
while(running)
{
c=a+b;
count++;
a=b;
b=c;
System.out.println("Fibonacci Series Thread :" + c);
if(count == no)
running = false;
t1.sleep(200);
}
}catch(InterruptedException e){e.printStackTrace(); }
}
}
class fib
{
public static void main(String ar[])
{
FibbThread t2=new FibbThread(10);
}
}
/*
Output:
H:\printout\Thread\1>java fib
Fibonacci Series Thread :1
Fibonacci Series Thread :2
Fibonacci Series Thread :3
Fibonacci Series Thread :5
Fibonacci Series Thread :8
Fibonacci Series Thread :13
Fibonacci Series Thread :21
Fibonacci Series Thread :34
Fibonacci Series Thread :55
Fibonacci Series Thread :89
*/
Post a Comment