Java: Declaring a multidimensional array without specifying the size of the array ( eg. new int[10][] )

前端 未结 6 1257
忘掉有多难
忘掉有多难 2021-01-13 09:08

I\'ve been trying to figure out what exactly is happening here. I\'m just trying to figure out what the 2 lines are doing that I\'ve commented on below. I found this program

6条回答
  •  无人及你
    2021-01-13 09:26

    The first line makes an array of int arrays. There are 10 slots for int arrays created.

    The third line creates a new int array and puts it in one of the slots you made at first. The new int array has r+1 spaces for ints in it.

    So, the int array in position 0 will have 1 slot for an int. The int array in position 1 will have 2 slots for an int. The overall shape will be:

    [
        [0],
        [0,0],
        [0,0,0],
        ...,
        [0,0,0,0,0,0,0,0,0,0]
    ]
    

    which is hinted at with the variable name tri (it looks like a triangle)

提交回复
热议问题