有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!


共 (2) 个答案

  1. # 1 楼答案

    参差不齐(或参差不齐)数组是一组大小不同的数组。如果你说的是int,参数类型肯定是int [][]

    很难说是谁出了什么错,但你或你的教授肯定错过了什么——public static int myMethod(int [] myArray)绝对不需要破烂的数组

  2. # 2 楼答案

    由于java5可以在方法签名中使用varargs。也许你教授的意思是这样的。此方法打印一种锯齿状2d阵列:

    public static int myMethod(int[]... myArray) {
        System.out.println(Arrays.deepToString(myArray));
        return 0;
    }
    
    public static void main(String[] args) {
        myMethod(new int[2], new int[]{1, 2, 3}, null);
    }
    

    输出:

    [[0, 0], [1, 2, 3], null]