0
What is the different between arrays and arrays multi dimension?
do the right word is dimensional array or arrays dimensional? i don't know anything about array and i got a homework about tht. please help me.
4 Respuestas
+ 4
Not really sir , that is a jagged array , wich is different from a multidimensional array .
The jagged array is an array formed from many arrays .
The multidimesnsional array is an array that has a number off rows and a number of columns [3,4] , 3 is the number off rows and 4 the numbers of columns , {{1,2,3,4},{2,3,1,2},{3,4,9,88},{12,34,12,8}}
You see you cant have an array inside the mutidimensional that has more elements than other array . If you declared 4 columns , all the childs of multidimensional array must have 4 elements , like a matrix .
Instead the jagged array can have
{12,12,{12,12,12},{12,12}} .
Hope I helped you .
+ 3
You can think of Multi-dimensional arrays as "arrays of arrays". Mostly used with things such as board games or anything that involves having certain things in a row and certain things in a column like space invaders etc.
int [ ] array = new int [ size];
//the above is known as signle dimensional array
// the below is known as two dimensional array with a given row and columns
String [ ][ ] arrays = new String [rowsize][colSize];
You can even have more than 2 dimensional arrays but then things will start to get complex.
+ 1
An arraay is a collection of variables of the same type that are referred to by a common name.
A One-dimensional array is a list of related variables.
general form:
type[] array-name = new type[size];
The general form for initializing a one-dimensional array is shown here:
type[] array-name = {val1,val2,val3,...valN};
Multidimensional Arrays
one index indicates the row, the other indicates the column.
To declare a two-dimensional integer array table of size 10,20, you would write
int[ , ] table = new int[10,20];
+ 1
Two-dimensional array is the array in which the length of each row is the same for the entire array.
Jagged array is an array of arrays in which the length of each array can differ.
To declare a two-dimensional jagged array, you will use this general form:
type[ ] [ ] array-name = new type[size][ ];
size indicates the number of rows in the array.
Example: A jagged array of size 3.
int[][] jagged = new int[3][];
jaggged[0] = new int[3];
jagged[1] = new int[2];
jagged[2] = new int[1];
After this sequence executes, jagged looks like this:
jagged[0][0] jagged[0][1] jagged[0][2]
jagged[1][0] jagged[1][1]
jagged[2][0]
Now to assign the value 10 to element 2,1 of jagged you would use this statement:
jagged[2][0] = 10;