title: Print integers from 1 to 10 with only 5 Threads in a specific order
body: <p><strong>I have recently started with multi-threading in Java</strong></p>
  
  <p>I have an issue solving a problem where I have got only 5 <strong>Threads</strong> ranging from <strong><em>T1, T2,...T5</em></strong>. </p>
  
  <p>The task is to print numbers from 1 to 10 in the following order. </p>
  
  <pre><code>T1 -&gt; 1
  T2 -&gt; 2
  T3 -&gt; 3
  T4 -&gt; 4
  T5 -&gt; 5
  T1 -&gt; 6
  T2 -&gt; 7
  T3 -&gt; 8
  T4 -&gt; 9
  T5 -&gt; 10
  </code></pre>
  
  <p>I tried solving it with this piece of code.</p>
  
  <pre><code>public static void main(String[] args) throws InterruptedException {
      Counter counter = new Counter();
      Thread[] tArray = new Thread[] { new Thread(counter, "T1"), new Thread(counter, "T2"),
              new Thread(counter, "T3"), new Thread(counter, "T4"), new Thread(counter, "T5") };
      for (int i = 0; i &lt; 10; i++) {
          if (i &lt; 5) {
              tArray[i].start();
              tArray[i].join();
          } else {
              tArray[i - 5] = new Thread(counter, "T" + ((i - 5) + 1)); //Instantiating new Thread which is not allowed.
              tArray[i - 5].start();
              tArray[i - 5].join();
          }
      }
  }
  
  public class Counter implements Runnable {
  
      private int count = 0;
  
      @Override
      public synchronized void run() {
         System.out.println(Thread.currentThread().getName() + " -&gt; " + ++count);
      }
  
  }
  </code></pre>
  
  <p>But since only 5 threads are allowed my solution is not accepted since I am also instantiating <code>new Thread</code> in the <code>else</code> block of the <code>for</code> loop.</p>
  
  <p>Any help would be highly appreciated.</p>