//  Threaded Hello World
//
//   Compile:   javac Hello.java
//   Run:       java  Hello
import java.util.*;
class Hello {
    private static final int n = 5;
    public static void main(String[] args) {
        int i;
        Friend t[] = new Friend[n];
        
        System.out.println ("Hello from the main thread");
        for (i=0; i<n; i++) {
	    t[i] = new Friend(i);
            t[i].start();
        }
        for (i=0; i<n; i++) {
            try {
               t[i].join();
            } catch (java.lang.InterruptedException e) {};
        }
        System.out.println ("Goodbye from the main thread");
    }
}

class Friend extends Thread {
    private int me;
    
    public Friend (int i) {
	me  = i;
    }

    public void run() {
	System.out.println("Hello from thread " + me);
    }
}
