title: How To Print 3 Stacks On Screen In 3 Columns Of 7 In The Most Efficient Manner Java
body: <p>I'm having trouble coming up with a way to print three stacks to the screen in 3 columns of 7. It's basically like a card game. </p>
  
  <p>So far my method looks like this:</p>
  
  <pre><code>/**
   * Prints the cards to the screen.
   */
  private void printTrick() {
  
  
      for (int i = 0; i &lt; bigStack.size(); i++){
          leftStack.push(bigStack.pop());     
          middleStack.push(bigStack.pop());    
          rightStack.push(bigStack.pop());   
      }
  
      for (int j = 0; j &lt; 7; j++){
          System.out.print(leftStack.elementAt(j) + "\t");
          System.out.print(middleStack.elementAt(j) + "\t");
          System.out.print(rightStack.elementAt(j) + "\t");
          System.out.println();
      }
  }
  </code></pre>
  
  <p>All I want to do is print the numbers on the screen in 3 columns of 7. There is one way I can write it that does work which looks like:</p>
  
  <pre><code>/**
   * Prints the cards to the screen.
   */
  private void printTrick() {
  
  
      int i=0;
  
      while(i&lt;21)
      {
          left.push(bigStack.pop());
          i++;
          middle.push(bigStack.pop());
          i++;
          right.push(bigStack.pop());
          i++;
      }
  
      for (int j = 0; j &lt; 7; j++){
          System.out.print(leftStack.elementAt(j) + "\t");
          System.out.print(middleStack.elementAt(j) + "\t");
          System.out.print(rightStack.elementAt(j) + "\t");
          System.out.println();
      }
  }
  </code></pre>
  
  <p>But it looks inefficient with the three increments inside the while loop. So I was wondering if there was a more efficient way to make this work. And also if it is possible to have the three stacks printed to the screen using <strong>one</strong> System.out.println() method rather than the three that I have, because when I tried to use the + operator like this:</p>
  
  <p>System.out.println(leftStack.elementAt(j) + middleStack.elementAt(j) + rightStack.elementAt(j));</p>
  
  <p>I got a <strong>'bad operand types for binary operator '+' first type: Card second type: Card'</strong> error. I just presumed the:</p>
  
  <p>first type:Card second type Card</p>
  
  <p>meant I was trying to System.out.print(object + object + object); which now I've just learned I can't do.</p>
  
  <p>And also if there is a better way to print out the numbers in columns rather than the (" \t "); I'm using.</p>
  
  <p>Sorry if this seems trivial I'm not a very strong programmer yet any help would be very appreciated. Thanks</p>