1

board is a 3D array that has already been declared. I am trying to directly assign it a value, but, attempting to do so gives me a host of errors.

board[2][][] = {
    {10, 15, 19, 21, 22, 22, 21, 19, 15, 10},
    {15, 20, 24, 26, 27, 27, 26, 24, 20, 15},
    {19, 24, 28, 30, 31, 31, 30, 28, 24, 19},
    {21, 26, 30, 32, 33, 33, 32, 30, 26, 21},
    {22, 27, 31, 33, 34, 34, 33, 31, 27, 22},
    {22, 27, 31, 33, 34, 34, 33, 31, 27, 22},
    {21, 26, 30, 32, 33, 33, 32, 30, 26, 21},
    {19, 24, 28, 30, 31, 31, 30, 28, 24, 19},
    {15, 20, 24, 26, 27, 27, 26, 24, 20, 15},
    {10, 15, 19, 21, 22, 22, 21, 19, 15, 10}
};

Errors: I have no idea why this is happening.

Islingre
  • 2,030
  • 6
  • 18
Bengineer8
  • 11
  • 4

1 Answers1

2

Credit to Islingre

I am assuming that the 3d board is defined in a similar fashion.

int board[][][] = new int[3][][];

Then you can assign the 3rd element in the 1st dimension to have these other two dimensions. Remembering of course that arrays are 0 based.

board[2] = new int[][] {
{10, 15, 19, 21, 22, 22, 21, 19, 15, 10},
{15, 20, 24, 26, 27, 27, 26, 24, 20, 15},
{19, 24, 28, 30, 31, 31, 30, 28, 24, 19},
{21, 26, 30, 32, 33, 33, 32, 30, 26, 21},
{22, 27, 31, 33, 34, 34, 33, 31, 27, 22},
{22, 27, 31, 33, 34, 34, 33, 31, 27, 22},
{21, 26, 30, 32, 33, 33, 32, 30, 26, 21},
{19, 24, 28, 30, 31, 31, 30, 28, 24, 19},
{15, 20, 24, 26, 27, 27, 26, 24, 20, 15},
{10, 15, 19, 21, 22, 22, 21, 19, 15, 10}
};
fedup
  • 1,209
  • 11
  • 26