I want to read the following into a 2d jagged array:
3
7 4
2 4 6
8 5 9 3
I need to increase the column size on every input. I’m not exactly sure how to do it.
My code is as follows:
int col = 1;
int[][] values = new int[rows][col];
for(int i = 0; i < values.length; i++){
for(int j = 1; j < col; j++)
{
values[i][j] = kb.nextInt();
col++;
}
}
This should do it.
Basically, you start by defining how many rows your 2d array should have.
In the
forloop, you define the 1d array for each row with its length.