Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Java does not allow subindexing of arrays.</p> <p>What you are referring to is trivially possible in C, but in Java you will need to either:</p> <ul> <li>copy the data to new arrays</li> <li>use a custom class abstracting from storage.</li> </ul> <p>In java, there is no way that <code>foo[0]</code> <em>permanently refers</em> to the element <code>bar[3]</code> of another array.</p> <p>If you want to work with <code>int[][]</code>, you'll have to copy the arrays. <code>Arrays.copyOfRange</code> and <code>System.arraycopy</code> will be the most efficient choices, but at Sudoku size it does obviously not make much of a difference.</p> <p>For the second approach, write a custom <code>Matrix</code> class. For example</p> <pre><code>class Matrix { int[] flatStorage; int[] offsets; Matrix(int[] flatStorage, int[] offsets) { this.flatStorage = flatStorage; this.offsets = offsets; } void set(int x, int y, int val) { flatStorage[ offsets[x] + y ] = val; } int get(int x, int y) { return flatStorage[ offsets[x] + y ]; } } int[] sharedStorage = new int[27]; Arrays.fill(sharedStorage, -1); // Initialize with -1 int[] allOffsets = new int[]{0,9,18, 27,36,45, 54,63,72}; Matrix nineByNine = new Matrix(sharedStorage, allOffsets); Matrix northEast = new Matrix(sharedStorage, new int[]{6,15,24}); Matrix southEast = new Matrix(sharedStorage, new int[]{60,69,78}); nineByNine.set(1,7, 2); // Write to middle of upper right quadrant System.err.println(northEast.get(1, 1)); // Read - should be 2! </code></pre> <p>Add size information and similar things yourself.</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. 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