0

我正在尝试在多维数组中显式声明值。我不断收到大量错误消息

这是有问题的代码:

    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};

这在二维数组中是不允许的吗?
我已经阅读了有关数组的 java 文档

4

2 回答 2

3
int [][] test = {
        {1,2,3},
        {1,3,2},
        {2,3,1},
        {2,1,3},
        {3,2,1},
        {3,1,2}};
于 2013-10-04T08:03:15.350 回答
2

你有错误的语法。您必须指定要实例化的内容。

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};
于 2013-10-04T08:00:57.203 回答