title: Using printf() to format output as a grid
body: <p>I'm trying to grid an output using the printf() statement.</p>
  
  <p>The Strings are generated via a 2D array that is iterated with two for loops</p>
  
  <p>example:</p>
  
  <pre><code>    String[][] arr =
      {
        {"*", "2", "1", "*", "1"},
        {"*", "2", "1", "*", "1"},
        {"*", "2", "1", "*", "1"},
        {"*", "2", "1", "*", "1"},
        {"*", "2", "1", "*", "1"}
      }
  
      for(int i = 0; i &lt; arr.length; i++)
      {
         for(int j = 0; j &lt; arr[0].length; j++)
         {
            System.out.printf("%s", arr[i][j]);
         }
      }
  </code></pre>
  
  <p>I basically want the output just as it appears in the code (as a 5x5 grid) but the tutorials on formatting are not very easy to follow and most do not deal with this sort of format. </p>
  
  <p>Ideally, the output should look like this:</p>
  
  <pre><code>    * 2 1 * 1
      * 2 1 * 1
      * 2 1 * 1
      * 2 1 * 1
      * 2 1 * 1
  </code></pre>
  
  <p>My question is, besides how would I do this using the printf() characters, is will I come across any problems using these inside a nested for-loop? Also, I understand where the %s comes from, but any further symbol usage is beyond me. Could someone explain why they would use the symbol and characters they are using for this?</p>
  
  <p>Thank you very much.</p>