title: Java: Iterating over multidimensional arrays Concept
body: <p>I am try learn Java  since last 3 yrs, still i found i am very weak in Core java.</p>
  
  <p>I have the following doubt from the below code, please help me.</p>
  
  <ul>
  <li>why <code>nums[i][j]=(i+1)*(j+1);</code> , <code>(i+1)*(j+1)</code> is used with <code>+1</code>.</li>
  <li>why first <code>array[]</code> is used to intialize the for-each loop i.e in line <code>for(int x[]:nums)..</code></li>
  </ul>
  
  <p>Code:</p>
  
  <pre><code>//Use for-each style for on a 2-dimensional array
  //Code source:From online site
  public void foreachmultiarrya()
  {
  
      int nums[][]=new int [3] [5];
      //give nums some values
                for(int i=0;i&lt;3;i++)
          for(int j=0;j&lt;5;j++)
              nums[i][j]=(i+1)*(j+1);
      int sum=0;
      for(int x[]:nums)
      {
          for(int y:x)
          {
              System.out.println("Value of y:"+y);
              sum+=y;
          }
      }
          System.out.println("Sum="+sum);   
  }
  </code></pre>