Hi Guys! Can you kindly run this code in your PC and see if are getting the correct output.... maybe there is something wrong with the path variable etc in my system...
thanks
I want to print numbers from 1 to 10 using two different Threads.
The code below is from a text book.....
I get the output correct sometimes, but when I re run the code, I get different output like 10 8 6 7 5 ... etc
public class CountDownApp
{
public static void main(String[] args)
{
Thread count1 = new CountDownEven();
Thread count2 = new CountDownOdd();
count1.start();
count2.start();
}
}
class CountDownEven extends Thread
{
public void run()
{
for(int i=10;i>0;i-=2)
{
System.out.println(this.getName()+"count"+i);
Thread.yield();
}
}
}
class CountDownOdd extends Thread
{
public void run()
{
for(int i=9;i>0;i-=2)
{
System.out.println(this.getName()+"count"+i);
Thread.yield();
}
}
}
[/b]
any hints appreciated