得到错误,当3D阵列声明 [英] getting error while 3D array declare

查看:84
本文介绍了得到错误,当3D阵列声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能是我使用的三维数组的第一次。我只是尝试按照一维和二维语法来声明3D,但编译器说类型不匹配。谁能告诉我这背后的原因是什么?

May be I am using 3D arrays first time. I just try to follow the 1D and 2D syntax to declare 3D, but compiler says Type mismatch. Can anyone tell me the reason behind this?

Integer[] _1D = new Integer[]{2,4,6,5,6};
Integer[][] _2D = new Integer[][]{{2,3},{4,6},{5,6}};
Integer[][][] _3D = new Integer[][][]{{1,2,3},{4,5,6},{7,8,9},{2,4,5}};

谢谢,

推荐答案

你只是创建的 2-D阵列的了,但与 4行3列的。这是创建一个三维数组的正确途径。

You're just creating a 2-d array again, but with 4 rows and 3 columns. This is the right way to create a 3-d array.

Integer[][][] _3D = new Integer[][][]{{{1,2,3},{4,5,6},{7,8,9},{2,4,5}},{{1,2,3},{4,5,6},{7,8,9},{2,4,5}}}; // it should be like this.

这篇关于得到错误,当3D阵列声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆