Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>int A[2][3]={{1,2,3},{4,5,6}}; </code></pre> <p>A 2D array is stored in the memory as follows. Entries in row 0 are stored first followed by row 1 and so on.</p> <p><img src="https://i.stack.imgur.com/1TTUj.png" alt="enter image description here"></p> <p>2-D arrays are represented as a contiguous block of n blocks each with size m (i.e. can hold m integers(or any data type) in each block). The entries are stored in the memory as shown above.Here n represent the number of rows and m represents the number of columns.</p> <p><strong>In Java:</strong></p> <p>As with all arrays, the new keyword must be used to allocate memory for an array. For example,</p> <pre><code> int[][] a = new int[2][4]; </code></pre> <p>This two-dimensional array will have two rows and four columns. This actually allocates 3 objects: a one-dimensional array of 2 elements to hold each of the actual row arrays, and two one-dimensional arrays of 4 elements to represent the contents of the rows.</p> <pre><code> +-----+ +-----+-----+-----+-----+ |a[0] | -&gt; | [0] | [1] | [2] | [3] | | | +-----+-----+-----+-----+ In Java two-dimensional arrays are implemented is a one-dimensional array of one-dimensional arrays -- like this. +-----+ | | +-----+-----+-----+-----+ |a[1] | -&gt; | [0] | [1] | [2] | [3] | +-----+ +-----+-----+-----+-----+ </code></pre> <p>In your case:</p> <pre><code>double[][] array2D = new double [max][1] </code></pre> <p>This actually allocates max+1 objects: a one-dimensional array of max elements to hold each of the actual row arrays, and max one-dimensional arrays of 1 elements to represent the contents of the rows.</p> <p>Let me know if I am wroung .</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload