title: Nested for loop to print output of 2D array in Java
body: <p>I have been struggling with the following problem:</p>
  <p>I am trying to print the below output using nested for loops and two dimensional arrays.</p>
  <pre class="lang-java prettyprint-override"><code>int[][] outputArray = {
      {1,2,3,4,5,6,7,8,9,10},
      {11,12,13,14,15,16,17,18,19,20},
      {21,22,23,24,25,26,27,28,29,30},
      {31,32,33,34,35,36,37,38,39,40},
      {41,42,43,44,45,46,47,48,49,50},
      {51,52,53,54,55,56,57,58,59,60},
      {61,62,63,64,65,66,67,68,69,70},
      {71,72,73,74,75,76,77,78,79,80}
  };
  </code></pre>
  <p>Here is my code for the array which seems to be correct:</p>
  <pre class="lang-java prettyprint-override"><code>public ExerciseTwo() {
      myArray1 = new int[8][10];
  
      for (int i = 0; i &lt; myArray1.length; i++) {
          for (int j = 0; j &lt; myArray1[i].length; j++) {
              myArray1[i][j] = (i * myArray1[i].length) + j + 1;
          }// end inner loop
      }// end outer loop
  }// end constructor
  </code></pre>
  <p>Now I am having several issues with the nested loop below:</p>
  <pre class="lang-java prettyprint-override"><code>public void printArrayStatement() {
      System.out.print(&quot;int[][] outputArray = {&quot;);
  
      for (int i = 0; i &lt; myArray1.length; i++) {
          if (myArray1.length &gt;= 1)
              // I am trying to remove the initial comma here but my
              // logic is wrong. It is printing 1 first on each line.
              System.out.print(&quot;\n&quot; + &quot;{&quot; + myArray1[0][0]); 
          for (int j = 0; j &lt; myArray1[i].length; j++) {
              System.out.print(&quot;,&quot; + myArray1[i][j]);
          }
      }
      System.out.println(&quot;};&quot;);
  }// end method
  </code></pre>
  <p>I also can't seem to figure out how to get the }, at the end of each line. I think an if statement is necessary but I can't figure out the code!</p>