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

前端 未结 6 1295
忘掉有多难
忘掉有多难 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:29

    It makes more sense if you think of a multidimensional array as an array of arrays:

    int [][] tri = new int[10][]; // This is an array of 10 arrays
    
    tri[r] = new int[r+1]; // This is setting the r'th array to
                           // a new array of r+1 ints
    

提交回复
热议问题