title: Java Threads: How to print alphabets and numbers using two threads one at a time
body: <p>I am trying to work around with threads in java. Though I understand that threads output are unpredictable, However was wondering if there is a way to do that. </p>
  
  <p>I have to implement two threads, one prints alphabets<code>(a,b,c...z)</code> and other prints numbers<code>(1,2,3....26)</code>. Have to implement it in such a way that the output should be <code>a,1,b,2,c,3,d,4......z,26</code>. Below is my code but it doesn't give the desired output.</p>
  
  <pre><code>public class ThreadsExample {
  
    public static void main(String[] args) {
      Runnable r = new Runnable1();
      Thread t = new Thread(r);
      Runnable r2 = new Runnable2();
      Thread t2 = new Thread(r2);
      t.start();
      t2.start();
    }
  }
  
  class Runnable2 implements Runnable{
    public void run(){
      for(char i='a';i&lt;='z';i++) {
          System.out.print(i+",");
      }
    }
  }
  
   class Runnable1 implements Runnable{
    public void run(){
      for(int i=1;i&lt;=26;i++) {
         System.out.print(i+",");
      }
   }
  }
  </code></pre>
  
  <p>What tweak should I make in the code to get the desired output? How does <code>synchronization</code> helps here? Or is it really possible when working with Threads at all?</p>
  
  <p>PS: This is not an assignment or some exercise. Its self learning.</p>