//===============================================================
// Using threads by extending the Thread class
// Create 2 threads and output odd/even numbers.
//===============================================================
public class Count1
{
    public static void main(String[] args)
    {
        Thread     odd  = new Count1Odd();     //instantiate a thread 
        Count1Even even = new Count1Even();    //or this way

        odd.start();                           //make it eligible for the scheduler to run it
        even.start();                         
    }
}

class Count1Odd extends Thread
{
    public void run( )
    {
        for (int odd = 1; odd <= 100; odd += 2)
        {
            System.out.println( this.getName( ) + " - count: " +  odd);

//          Thread.yield( );              //yield so other threads can execute
        }                                 //if so, the 2 threads alternate execution
    }
}

class Count1Even extends Thread
{
    public void run( )
    {
        for (int even = 2; even <= 100; even += 2)
        {
            System.out.println("\t\t\t" + this.getName( ) + " - count: " +  even);

//          Thread.yield( );
        }
    }
}