Program :-
class th1 extends Thread
{
public void run()
{
for(int i=1;i<=10;i++)
{
while(ThMain.b1)
{}
System.out.println("Thread one: "+i);
ThMain.b1=true;
ThMain.b2=false;
}
}
}
class th2 extends Thread
{
public void run()
{
for(int i=10;i>=1;i--)
{
while(ThMain.b2)
{}
System.out.println("Thread two: "+i);
ThMain.b1=false;
ThMain.b2=true;
}
}
}
public class ThMain
{
public static boolean b1=false;
public static boolean b2=false;
public static void main(String a[])
{
th1 t1=new th1();
th2 t2=new th2();
t1.start();
t2.start();
}
}
______________________________________________________________________
Please Subscrbe channel on Youtube
link - youtube.com/CAPTURINGEYE