Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
多维数组中的Java显式声明_Java_Arrays_Multidimensional Array - Fatal编程技术网

多维数组中的Java显式声明

多维数组中的Java显式声明,java,arrays,multidimensional-array,Java,Arrays,Multidimensional Array,我试图在多维数组中显式声明值。 我不断收到大量错误消息 以下是违规代码: 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文档您的语法错误。您

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

以下是违规代码:

    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文档

您的语法错误。您必须指定要实例化的对象

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

你的语法错了。您必须指定要实例化的对象

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

您收到的错误是什么?应为错误']',错误:表达式的非法开始,错误表达式的非法开始和错误不是第2行的语句您收到的错误是什么?应为错误']',错误:表达式的非法开始,错误表达式的非法开始和错误不是第2行的语句,我在这个问题上花费了大量的时间。另外,如果OP是这样做的,他们不需要将数组的第二维度初始化为[3]。当后退的线初始化这些元素时,他们可以将数组初始化为
new int[6][]
。感谢Milan,我在这个问题上花费了过多的时间。此外,如果OP这样做,他们不需要将数组的第二维度初始化为[3]。当后退的行初始化这些元素时,它们可以将数组初始化为
newint[6][