2D Arrays

I need to create the constructor -- public Puzzle(int[] numbers) -- to initialize puzzle (9x9 game card) from an array of integers assuming that the parameter array numbers will contain 81 integers between 0 and 9 inclusive. The constructor will have to fill the puzzle row by row.

How would such a constructor look?

[329 byte] By [Scorpionna] at [2007-11-26 15:43:49]
# 1

This is a straightforward approach...

...

for (i = 0; i <9; i++){

for(j = 0; j < 9; j++){

array2D[i][j] = numbers[(i*9) + j];

}

}

...

You'll have that array2D (int[][]) within your class.

Is this what you're asking for? I am not really sure about this, but I think it'd work...

Lord_Randala at 2007-7-8 22:02:49 > top of Java-index,Desktop,Developing for the Desktop...