I have this code below as I saw from textbook
public static int[][] Pascal(int N) {
int[][] result = new int[N][]; // Build a grid with specific number of rolls
for (int i = 0; i < N; i += 1) {
result[i] = new int[i + 1]; // Build an empty row with length
result[i][0] = result[i][i] = 1;
for (int j = 1; j < i; j += 1) {
result[i][j] = result[i - 1][j - 1] + result[i - 1][j];
}
}
return result;
}
I have no question for how this Pascal triangle is achieved, all very clear.
However, I did learned before that to create an Array, length must be given,
for example, int[] A = int[];
will give me Error
It has to be int[] A = int[N];
or int[] A = int[]{1,2,3,etc.};
So when we create the array grid int[][] result = new int[N][];
How is it allow me to only specify the number of rows, but leave the length of each row with blank?
I did noticed that the length of each roll was defined later at result[i] = new int[i + 1];
, I still don't understand why this grid is allowed to be initiated.
Thanks!