Vous êtes sur la page 1sur 14

Estructura de Datos

Arreglos Bidimensionales en Java

Objetivos Especficos
Reconocer un arreglo bidimensional. Construir aplicaciones con arreglos.

Contenido
ARREGLOS BIDIMENSIONALES Operaciones bsicas :
ingreso, listado, modificacin, ordenamiento.

Arreglos Bidimensionales Java


Declaracin
int mat[][];

Creacin
mat = new int[3][5];

Arreglos Bidimensionales Java


Declaracin y creacin
int mat[][] = new int[3][5];
nombre del arreglo
FILAS COLUMNAS

num. FILAS :

mat.length
num. COLUMNAS :

mat
i 0

j 0
53 36 37

1
43 49 59

2
91 95 62

3
68 49 67

4
72 84 85

mat[i].length
Se usa una fila cualquiera

1 2

Problemas : Autoevaluacin
Se tiene un arreglo bidimensional de 4X6

mat
i
0 1 2

j
Reporte: 0 1 2 3 4 5
53 36 37 12 43 49 59 95 91 95 62 36 68 49 67 29 72 84 85 13 62 39 70 71

1. 2. 3. 4. 5.

Cantidad de nmeros. Suma de los nmeros. Promedio. Menor nmero. Mayor nmero.

FILAS*COLUMNAS Recorrer acumular sumapara / cantidad

Suma de los nmeros de cada fila


0 suma =187 327 255 85 36 389 96 37 0 352 225 313 229 180 158 380 310 107 96 256 53 172 0 12 143 185
acumulador

mat
i i
i i
0
1 2 3

j
0
53
36 37 12

1
43
49 59 95

2
91
95 62 36

3
68
49 67 29

4
72
84 85 13

5
62
39 70 71

389 352 380 256

FILAS 4 COLUMNAS 6

Suma de los nmeros de cada columna

mat
i
0 1 2

j
0
53 36 37 12

1
43 49 59 95

2
91 95 62 36

3
68 49 67 29

4
72 84 85 13

5
62 39 70 71

138 246

Suma de elementos que forman letra L

mat
0 1 2

j
0
53 36 37 12

1
43 49 59 95

2
91 95 62 36

3
68 49 67 29

4
72 84 85 13

5
62 39 70 71

ALGORITMO Recorrer todo el arreglo y sumar slo los elementos que se ubiquen en: - Primera columna. - ltima fila.

j=0 i = FILAS - 1

FILAS 4 COLUMNAS 6

Suma de elementos que forman letra J

mat
0 0 1 2
53 36 37 12

j
1
43 49 59 95

2
91 95 62 36

3
68 49 67 29

4
72 84 85 13

5
62 39 70 71

ALGORITMO Recorrer todo el arreglo y sumar slo los elementos que se ubiquen en: - ltima fila. - ltima columna.

i = FILAS - 1 j = COLUMNAS - 1

FILAS 4 COLUMNAS 6

Suma de elementos que forman letra U

mat
0 1 2

j
0
53 36 37 12

j
1
43 49 59 95

2
91 95 62 36

3
68 49 67 29

4
72 84 85 13

5
62 39 70 71

ALGORITMO Recorrer todo el arreglo y sumar slo los elementos que se ubiquen en: - Primera columna. - ltima columna. - ltima fila.

j=0 j = COLUMNAS 1 i = FILAS - 1

FILAS 4 COLUMNAS 6

Suma de elementos que forman letra O

mat
i
0 1 2

j
0
53 36 37 12

j
1
43 49 59 95

2
91 95 62 36

3
68 49 67 29

4
72 84 85 13

5
62 39 70 71

ALGORITMO Recorrer todo el arreglo y sumar slo los elementos que se ubiquen en: - Primera fila. - ltima fila. - Primera columna. - ltima columna.

FILAS 4 COLUMNAS 6

i=0 i = FILAS - 1 j=0 j = COLUMNAS 1

Menor nmero de cada fila


menor = 53 menor = 43

mat
i
0 1

j
0
53 36

1
43 49

2
91 95

3
68 49

4
72 84

5
62 39

2 3

37 12

59 95

62 36

67 29

85 13

70 71

Desplazar hacia la izquierda


mat
i
0 1 2 aux =

j
0
53 53 36 37 12

1
43 43 49 59 95

2
91 91 95 62 36

3
68 68 49 67 29

4
72 72 84 85 13

5
62 62 39 70 71

Desplazar hacia la derecha


mat
i
0 1 2 aux =

j
0
53 53 36 37 12

1
43 43 49 59 95

2
91 91 95 62 36

3
68 68 49 67 29

4
72 72 84 85 13

5
62 62 39 70 71

Vous aimerez peut-être aussi