Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.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_Multidimensional Array - Fatal编程技术网

Java非均匀多维数组

Java非均匀多维数组,java,multidimensional-array,Java,Multidimensional Array,我是根据这段代码来的,我不确定到底发生了什么。内容如下: int twod [] [] = new int[4][];// i know the first one is row twod [0] = new int[1];// twod [1] = new int[2];// What are these? twod [2] = new int[3];// twod [3] = new int[4];// 最

我是根据这段代码来的,我不确定到底发生了什么。内容如下:

       int twod [] [] = new int[4][];// i know the first one is row

       twod [0]  = new int[1];//
       twod [1]  = new int[2];//  What are these? 
       twod [2]  = new int[3];//
       twod [3]  = new int[4];//

最后4行在做什么?

上面的代码没有编译。但我有一种强烈的感觉,OP的意思是:

   int twod[][] = new int[4][];// i know the first one is row

   twod[0] = new int[1];
   twod[1] = new int[2];
   twod[2] = new int[3];
   twod[3] = new int[4];
这将创建以下形状的数组(向上->向下=第一维度,向左->向右=第二维度):

更具体地说,当我们查询数组的长度时,我们会得到以下结果:

twod.length -> 4
twod[0].length -> 1
twod[1].length -> 2
twod[2].length -> 3
twod[3].length -> 4

你发布的内容没有为我编译。我想这就是你想要的锯齿阵列

   int twod [][] = new int[4][];// i know the first one is row

   twod[0] = new int[1];//
   twod[1] = new int[2];//  What are these? 
   twod[2] = new int[3];//
   twod[3] = new int[4];//
结果(在调试中):


@pbabcdefp代码部分来自完整的参考资料赫伯特·席尔德第九版。是的,它是编译的,并且在程序中也有输出,我只需要知道它是做什么的。@Dhananjay,它不编译。例如在
twod[][]=newint[1]上我得到:-语法错误,插入“.class”以完成表达式-赋值的左侧必须是variable@Turing85:我只记得在c中被称为锯齿数组的东西。不相似,但我想我可以单独分配剩余尺寸。供您参考。。。明白了谢谢你的参考Guyseyah完全是出于同样的目的这不是编译。。。我用的是netbeans,上面我也修改了我的语法,显然我同时使用了netbeans和eclipse。但这正是困扰我的问题,它是如何工作的。明白了,这是为了修正划船的长度。是的,我在那里看到了我的错误。但我还是不知道发生了什么。对不起,我是个菜鸟简单地说。。。这是不同列数的行。你的意思是这是一种实际修改整行的方法,意思是如果我需要,我可以让第二行有10列,第三行有5列,第四行有7列。。。所以基本上,我可以选择以任何方式修改行或列?这是正确的。这一切都取决于你的用例,你希望一个数组有多锯齿。。。另一份学习参考书谢谢你的参考书我现在拿到了全部资料。。毫无疑问,现在还剩下,谢谢。。
   int twod [][] = new int[4][];// i know the first one is row

   twod[0] = new int[1];//
   twod[1] = new int[2];//  What are these? 
   twod[2] = new int[3];//
   twod[3] = new int[4];//