Arreglos Bidimensionales Arreglos Multidimensionales
INGRESOS MENSUALES POR VENTAS MI AGENDA DE AMIGOS CentroMaribel Villa FátimaAgustín Villa FátimaJorge
Un arreglo bidimensional es un conjunto de datos homogéneo, finito y ordenado, donde se hace referencia a cada elemento por medio de dos índices. El primero se utiliza para indicar el renglón o fila y el segundo para indicar la columna. También puede definirse como un vector de vectores.
M[0][0]M[0][1]M[0][2]...M[0][m] M[1][0]M[1][1]M[1][2]...M[1][m] M[2][0]M[2][1]M[2][2]...M[2][m] M[n][0]M[n][1]M[n][2]...M[n][m] m 012:n012:n
M[0][0]M[0][1]M[0][2] M[1][0]M[1][1]M[1][2] M[2][0]M[2][1]M[2][2] M[3][0]M[3][1]M[3][2]
M[0][0]=3 M[0][1]=6 M[0][2]=-1 M[1][0]=5 M[1][1]=2 M[1][2]=11 M[2][0]=9 M[2][1]=1 M[2][2]=4 M[3][0]=21 M[3][1]=7 M[3][2]=8
TIPO TAMAÑO RANGO(Valores numéricos de ) byte 8 bits–128 a 127 short 16 bits– a int 32 bits– a long 64 bitssin límite. float 32 bitshasta 38 cifras double64 bitshasta 308 cifras char 16 bitsValores alfanuméricos String Según long para cadenas de caracteres boolean 8 bitsSolo admite TRUE o FALSE
Declaración de una matriz y Asignación en una matriz int [ ] [ ] matriz1; matriz1 = new int [ 2] [ 3 ]; int [ ] [ ] matriz2 = new int [ 2 ] [ 3 ]; int [ ] [ ] matriz3 = { {3, 4, 8},{1, 2, 5} };
int [ ] [ ] matriz1; equivale a escribir: int matriz1 [ ] [ ] ; int [ ] [ ] matriz3 = { { 3, 4, 8 }, { 1, 2, 5 } }; equivale a escribir int matriz3 [ ] [ ] = { { 3, 4, 8 }, { 1, 2, 5 } };
Operaciones con matrices num = a[2][1] + a[3][1] + 2; dando como resultado num = = 61. a[0] [2]= (int) (Math.pow(a[2] [1], 2)) ; dando a[0] [2]= 4. a[0] [2]= a[0] [0] + a[1] [0] + a[2] [0]; dando a[0] [2]= = 7. a[0] [2] = a[1] [0] / a[0] [0]; dando a[0] [2] = -8. Es importante recalcar que en este caso ni a[1] [0], ni a[0] [0] alteran su contenido.
USO DE LA VARIABLE length Devuelve un entero que nos permite conocer la cantidad de elementos de un arreglo int num_fil; Int num_col; num_fil = D.length ; num_col = D[0].length;
int a [ ] [ ] = { {0, 3, 4, 8}, {1, 5}, {2, 9, 2}, {1}, {2, 4, 1, 7} } ; int num_fil; Int num_col; num_fil = D.length ; num_col0 = D[0].length; num_col1 = D[1].length; num_col2 = D[2].length; num_col3 = D[3].length; num_col4 = D[4].length;
class FunMatrices { metodoX ( tipo_de_mat Matriz [ ] [ ] ) { } public static void main (String args[]) { FunMatrices A= new FunMatrices(); tipo_de_mat M [ ] [ ] = new tipo_de_mat [ 4 ][4 ]; A. metodoX ( M ) ; }
El numero de dimensiones depende del lenguaje elegido. Los vectores y matrices solo son casos especiales de los arreglos multidimensionales. Por ejemplo un arreglo de tres dimensiones.
M(0,0,0)M(0,1,0) M(1,0,0)M(1,1,0) M(2,0,0)M(2,1,0) M(0,0,2)M(0,1,2) M(1,0,2)M(1,1,2) M(2,0,2)M(2,1,2) M(0,0,1)M(0,1,1) M(1,0,1)M(1,1,1) M(2,0,1)M(2,1,1)
int ArregloMultiDimen [ ] [ ] [ ] = new int int [ 2 ] [ 4 ] [ 5 ] ;
Gracias por su atención