title: Different output based on the way I invoke a get() method
body: <p>Given the below code in the <code>main()</code> method when calling <code>get()</code> method in class <code>Queue</code> the output differs when I do this in a way put forward below:</p>
  
  <p><strong>All letters shown in the output of this code as expected</strong> :</p>
  
  <pre><code>class Queue {
      char get() {
          if (getlock == putlock) {
              System.out.println("-Queue is empty");
              return (char) 0;
          }
          return q[getlock++];
      }
  }
  
  public static void main(String[] args) {
      Queue bigQ = new Queue(100);
      Queue smallQ = new Queue(4);
  
      char ch;
      int i;
  
      System.out.println("Using bigQ to store the alphabet. ");
      for (i = 0; i &lt; 26; i++)
          bigQ.put((char)('A' + i));
  
      System.out.print("Contents of bigQ: ");
  
      for (i = 0; i &lt; 26; i++) {
          ch = bigQ.get();
          if (ch != (char) 0)
              System.out.print(ch);
      }
  }
  </code></pre>
  
  <p>However, when I don't use <code>char ch</code> in the <code>main()</code> but instead repeatedly call <code>bigQ.get()</code> directly, it shows only every third letter. I am tired and cannot understand why. The changed fragment of code is below:</p>
  
  <p><strong>Only every third letters is shown in the output of this code</strong></p>
  
  <pre><code>    for (i = 0; i &lt; 26; i++) {
          bigQ.get(); 
          if (bigQ.get() != (char) 0)     
              System.out.print(bigQ.get());
      }
  </code></pre>
  
  <p>Small change and such a difference. I would be grateful if you would let me know why this is, because I really don't get it.</p>