title: Java display output in columns/rows
body: <p>I'm trying to display the output as columns instead of what I'm currently getting and they're all over the place. I want it to look somewhat like this:</p>
  
  <p>Account "Account1":</p>
  
  <p>0(1) 16 16,</p>
  
  <p>1(0) 12 12,</p>
  
  <p>2(2) 0 0  </p>
  
  <p>I've tried using \t as separators and printf but cannot figure it out.
  Apologies if the code is poorly formatted, I'm still fairly new to coding</p>
  
  <p>I appreciate any help or tips </p>
  
  <p><strong>Account.java</strong></p>
  
  <pre><code>import java.util.ArrayList;
  
  public class Account {
  private static String name;
  private int balance;
  int Transactions; 
  
  private static ArrayList&lt;String&gt; array = new ArrayList&lt;String&gt;(); // array list
  
  /**
   * @param args
   */
  public static void main(String[] args) {
      // Check to make sure program has been called with correct number of
      // command line arguments
      if (args.length != 3) {
          System.err.println("Error: program should take exactly three command line arguments:");
          System.err.println("\t&lt;No. of card holders&gt; &lt;main acct starting bal.&gt; &lt;backup acct. starting bal.&gt;");
          System.exit(0);
      }
      // And then make sure that those args are all integers
      try {
          int numCards = Integer.parseInt(args[0]);
          Account account = new Account("Account1", Integer.parseInt(args[1]));
  
          // Your code to create and manage the threads should go here.
          Thread[] threads = new Thread[numCards];
          for (int i = 0; i &lt; numCards; i++) {
              threads[i] = new Thread(new CardHolder(i, account));
              threads[i].start();
          }
          for (int i = 0; i &lt; numCards; i++) {
              threads[i].join();
          }
      } catch (Exception e) {
          System.err.println("All three arguments should be integers");
          System.err.println("\t&lt;No. of card holders&gt; &lt;main acct starting bal.&gt; &lt;backup acct. starting bal.&gt;");
      }
      printStatement();
  }
  
  // Create an account - initalisation goes in here
  public Account(String name, int bal) {
      Account.name = name;
      this.balance = bal;
  }
  
  // Deposit &lt;balance&gt; into the account
  public synchronized void deposit(int cardholder, int balance) {
      balance = balance + balance;
      notify();
      array.add(array.size()+"("+cardholder+")"+"\t"+"\t"+balance+"\t"+ balance+"\n");
      cardholder++;
  }
  
  // Withdraw &lt;balance&gt; from the account
  public synchronized void withdraw(int cardholder, int balance) {
  
      if (balance &lt; balance) {  //
          try {
              System.err.println("Not enough money");
              wait();
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
      balance = balance - balance;
      array.add(array.size()+"("+cardholder+")"+"\t"+balance+"\t"+"\t"+ balance+"\n");
      cardholder++;
  }
  
  
  // Print out the statement of transactions
  public static void printStatement() { 
      System.out.printf("%s\n", "Account \"" +  name + "\":"); // cant figure out how to arrange it into rows/columns
  
      System.out.println(array);
   }
  }
  </code></pre>
  
  <p><strong>CardHolder.java</strong></p>
  
  <pre><code>public class CardHolder implements Runnable {
  private int id;
  private Account account;
  final static int numIterations = 20;
  
  public CardHolder(int id, Account account) {
      this.id = id;
      this.account = account;
  }
  
  /*
   * run method is what is executed when you start a Thread that
   * is initialised with an instance of this class.
   * You will need to add code to keep track of local balance (cash
   * in hand) and report this when the thread completes.
   */
  public void run() {
      for (int i = 0; i &lt; numIterations; i++) {
          // Generate a random amount from 1-10
          int amount = (int)(Math.random()*10)+1;
          // Then with 50/50 chance, either deposit or withdraw it
          if (Math.random() &gt; 0.5) {
              account.withdraw(id, amount); 
          } else {
              account.deposit(id, amount); 
          }
          try {
              Thread.sleep(200);
          } catch (InterruptedException e) {
              e.printStackTrace();
          } 
      }
      System.out.println("THREAD "+ id + " finished"); 
  
   }
  }
  </code></pre>