Professional Documents
Culture Documents
(ARRAYS)
void main(){
int nota1, nota2, nota3,……nota1000;
}
Nota 1000
Nota 2
Nota 3
ARREGLOS UNIDIMENSIONALES
ARREGLOS UNIDIMENSIONALES
Inicialización:
float precios[];
precios = new float [80];
<arreglo>[<indice>] = <sentencia>;
<variable> = <arreglo>[<indice>];
String[] ciudades = {
"Madrid", "Barcelona", "Bilbo", "Donosti",
"Gasteiz", "Iruña"
};
Obtener
el valor:
<nombre>[<posición>]
int a = precios[8]
Guardar
valor:
<nombre>[<posición>] = valor
precios[6] = 50;
ARREGLOS UNIDIMENSIONALES
EJEMPLO 1
static void main(….){
0
int numeros[]=new int [10]; 1
int i; 2
3
for(i=0;i<10;i++) 4
numeros[i]=i; 5
6
for(i=0;i<10;i++) 7
System.out.println(numeros[i]); 8
9
}
ARREGLOS UNIDIMENSIONALES
EJEMPLO 2
static void main(){
for(i=0;i<10;i++)
numeros[i]=ent.nextInt();
for(i=0;i<10;i++)
System.out.println(numeros[i]);
}
ARREGLOS UNIDIMENSIONALES
EJEMPLO 3
for(i=0;i<N;i++)
numeros[i]=ent.nextInt();
sum=0;
for(i=0;i<N;i++){
sum = sum + numeros[i];
}
System.out.println(sum);
}
PASO DE ARREGLOS A FUNCIONES
Recorrido
PASO DE ARREGLOS A FUNCIONES
Recorrido
ARREGLOS MULTIDIMENSIONALES
ARREGLOS MULTIDIMENSIONALES
<tipo> <nombre>[][]...
double precios[][];
Inicialización:
<nombre> = new <tipo>[filas][columnas];
precios = new double[80][40]; //array de 80x40
ARREGLOS MULTIDIMENSIONALES
Obtener
el valor:
<nombre>[fila][columna]
double a = precios[8][10];
Guardar
valor:
<nombre>[fil][col] = valor
precios[6][12] = 50,34;