如何在代码中硬定义矩阵 Integer[][]

Posted

技术标签:

【中文标题】如何在代码中硬定义矩阵 Integer[][]【英文标题】:How to hard define in code a matrix Integer[][] 【发布时间】:2011-02-22 00:46:48 【问题描述】:

专家的问题很简单

Integer[][] res= new Integer[][] .....hard code some values here on 2 dim...

如何像这样返回 2 行和 3 列

1 2 3
4 5 6

【问题讨论】:

【参考方案1】:
int[][] res = 1,2,3,
               4,5,6;

【讨论】:

很好,但问题不是要整数而不是整数吗?有细微的差别...... @mikera:您可以将 int[] 转换为 Integer[]【参考方案2】:

这应该可行。 (但我不是 Java 专家)。

Integer [][] ints =  1, 2, 3, 4, 5, 6 ;

【讨论】:

以上是关于如何在代码中硬定义矩阵 Integer[][]的主要内容,如果未能解决你的问题,请参考以下文章