Reputation: 53
I am trying to explicitly declare values in a multidimensional array. I keep getting a multitude of error messages
Here is the offending code:
int[][] test = new int [6][3];
test[0] = {1,2,3};
test[1] = {1,3,2};
test[2] = {2,3,1};
test[3] = {2,1,3};
test[4] = {3,2,1};
test[5] = {3,1,2};
Is this not allowed in 2 dimensional arrays?
I have read the java doc on arrays
Upvotes: 0
Views: 564
Reputation: 8548
int [][] test = {
{1,2,3},
{1,3,2},
{2,3,1},
{2,1,3},
{3,2,1},
{3,1,2}};
Upvotes: 3
Reputation: 4222
You had wrong syntax. You have to specify what to instantize.
int[][] test = new int [6][3];
test[0] = new int[]{1,2,3};
test[1] = new int[]{1,3,2};
test[2] = new int[]{2,3,1};
test[3] = new int[]{2,1,3};
test[4] = new int[]{3,2,1};
test[5] = new int[]{3,1,2};
Upvotes: 2