Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Why is it 21? I thought it would be 22.</p> </blockquote> <p>The example is wrong. It will be 22.</p> <blockquote> <p>I tried thePieces[0][0][0].length but got an error that I did not understand? </p> </blockquote> <p>This requires a little explanation. When you say:</p> <pre><code>int[][][] thePieces = { ... } </code></pre> <p>You are declaring a variable called thePieces to be an array of arrays of arrays of ints. That sounds funny. Anyway, thePieces.length is valid, because thePieces is an array of some sort. When you dereference the array, like so:</p> <pre><code>thePieces[index] </code></pre> <p>You get an array of arrays of ints, which you can call length on, because it is an array of something. SO:</p> <pre><code>thePieces[index0][index1] </code></pre> <p>is an array of ints, which you can call length on (I hope you see a pattern by now).</p> <pre><code>thePieces[index0][index1][index2] </code></pre> <p>Gives you a plain-old int, which does not have a length property.</p> <blockquote> <p>I ran my piece code and got 2. I have no idea why it is two. Is it because I have two sets at the third level? I expected to get four because of the four sets of points.</p> </blockquote> <p>You call:</p> <pre><code>System.out.println(thePieces[0][0].length); </code></pre> <p>Which prints 2 because thePieces[0] points to this array:</p> <pre><code>{ //square {0,0}, {1,0}, {1,1}, {0,1} } </code></pre> <p>which would return 4 (if you called thePieces[0].length). However, thePieces[0][0] points to:</p> <pre><code>{0, 0} </code></pre> <p>which has length of 2.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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