/* Main thread joining other threads to print end of line 
   when all have finished processing */

public class Test2 {

  static final int NUM_THREADS = 10;
  static MyThread2 myThreads[];

  public static void main(String[] argv){
    myThreads = new MyThread2[10];
    for (int i=0; i < NUM_THREADS; i++)
      myThreads[i] = createThread(i);
    for (int i=NUM_THREADS; i > 0;)
      myThreads[--i].start();
    try {
	myThreads[0].join();
    } catch (InterruptedException e){
	return;
    }
    System.out.println();
  }

  public static MyThread2 createThread(int i){
    return new MyThread2(new Integer(i).toString());
  }
}

class MyThread2 extends Thread{

  static final int NUM_PRINTS = 3;

  MyThread2(String s){
    super(s);
  }

  public void run(){
    for (int i=0; i < NUM_PRINTS; i++){
      System.out.print(getName());
    }
  }
}
