【问题标题】:How to hard define in code a matrix Integer[][]如何在代码中硬定义矩阵 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

【问题讨论】:

    标签: java arrays matrix


    【解决方案1】:
    int[][] res = {{1,2,3},
                   {4,5,6}};
    

    【讨论】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      • 2019-12-26
      • 1970-01-01
      • 2016-11-01
      • 1970-01-01
      相关资源
      最近更新 更多