I have quite a basic question.
For example:
int a[][] = {{1,2,3,4},{5,6,7,8},{9,10,11,12}}
we say it is [3][4] as it has 3 elements and each element has its own 4 elements.
but how about:
int a[][] = {{1},{5,6,7},{9,10,11,12}}
is it still [3][4]?
update
so based on the helpful comments below, my first example can be written as a [3][4] array, but the second one cannot be indicated like that, right?
We can declare a two-dimensional integer array say 'x' of size 10,20 as: int x[10][20]; Elements in two-dimensional arrays are commonly referred to by x[i][j] where i is the row number and 'j' is the column number.
Here is how we can initialize a 2-dimensional array in Java. int[][] a = { {1, 2, 3}, {4, 5, 6, 9}, {7}, }; As we can see, each element of the multidimensional array is an array itself. And also, unlike C/C++, each row of the multidimensional array in Java can be of different lengths.
Arrays can be created in 1D or 2D. 1D arrays are just one row of values, while 2D arrays contain a grid of values that has several rows/columns. 1D: 2D: An ArrayList is just like a 1D Array except it's length is unbounded and you can add as many elements as you need.
These are called Jagged Arrays, and they are not considered to be m-by-n, because they do not fit the formal definition of a Matrix.
In mathematics, a matrix (plural matrices) is a rectangular array of numbers, symbols, or expressions, arranged in rows and columns.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With