Syntax for creating a two-dimensional array

前端 未结 12 1207
悲&欢浪女
悲&欢浪女 2020-11-21 18:11

Consider:

int[][] multD = new int[5][];
multD[0] = new int[10];

Is this how you create a two-dimensional array with 5 rows and 10 columns?<

12条回答
  •  名媛妹妹
    2020-11-21 18:46

    Try:

    int[][] multD = new int[5][10];
    

    Note that in your code only the first line of the 2D array is initialized to 0. Line 2 to 5 don't even exist. If you try to print them you'll get null for everyone of them.

提交回复
热议问题