title: How to Correctly Add Values to a 3D Array in Java
body: <p>I am trying to create a three dimensional array that outputs as:</p>
  
  <pre><code>[1,2,3], [1,2,3], [1,2,3], [1,2,3]
  [1,2,3], [1,2,3], [1,2,3], [1,2,3]
  [1,2,3], [1,2,3], [1,2,3], [1,2,3]
  [1,2,3], [1,2,3], [1,2,3], [1,2,3]
  [1,2,3], [1,2,3], [1,2,3], [1,2,3]
  </code></pre>
  
  <p>Here is the code I have come up with:</p>
  
  <pre><code>public class Triples {
  
      public static void main(String[] args) {
  
          int[][][] triplet = new int[5][4][3];
  
          for (int i = 0; i &lt; triplet.length; i++) 
          {
              for (int j = 0; j &lt; triplet[i].length; j++) 
              {
                  System.out.print("[");
                  for (int k = 0; k &lt; triplet[i][j].length; k++) 
                  {
                      triplet[i][j][k] = i+1;
                      System.out.print(triplet[i][j][k] + "," + "");
                  }
                  System.out.print("]");
              }
              System.out.println();
          }
      }
  }
  </code></pre>
  
  <p>The result I have looks like:</p>
  
  <pre><code>[1,1,1,][1,1,1,][1,1,1,][1,1,1,]
  [2,2,2,][2,2,2,][2,2,2,][2,2,2,]
  [3,3,3,][3,3,3,][3,3,3,][3,3,3,]
  [4,4,4,][4,4,4,][4,4,4,][4,4,4,]
  [5,5,5,][5,5,5,][5,5,5,][5,5,5,]
  </code></pre>
  
  <p>My issue is I am not sure how to increment the values in the third for loop to go as 1, 2, and 3. I have tried different combinations, but they have resulted with either the same or incorrect result. Any tips? </p>