mirror of
https://gitlab.com/tutorial-java-rafa-munoz/tutorial-java-2024-25/tutorialjava2024-25.git
synced 2025-11-10 02:13:07 +01:00
feat(UtilsArrays): added
This commit is contained in:
@@ -9,8 +9,8 @@ public class Ej01_EjemploArraysPrimitivos {
|
||||
* @param args
|
||||
*/
|
||||
public static void main(String[] args) {
|
||||
primerEjemploArray();
|
||||
// segundoEjemploArray();
|
||||
// primerEjemploArray();
|
||||
segundoEjemploArray();
|
||||
// tercerEjemploArray();
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class Ej01_EjemploArraysPrimitivos {
|
||||
*/
|
||||
public static void segundoEjemploArray() {
|
||||
// Otra forma de inicializar el array
|
||||
int array2[] = new int[] {88, 89, 90, 4, 5, 6, 7, 8, 9, 10};
|
||||
int array2[] = new int[] {88, 89, 90, 4, 5, 8, 9, 10};
|
||||
|
||||
// Recorrido del array para imprimir sus valores en pantalla.
|
||||
// Este tipo de bucle se conoce como "for each".
|
||||
@@ -59,22 +59,22 @@ public class Ej01_EjemploArraysPrimitivos {
|
||||
float media;
|
||||
|
||||
// Declaración del array
|
||||
int array[] = new int[1000000];
|
||||
int array[] = new int[10];
|
||||
|
||||
// Recorro para inicializar el array
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
array[i] = (int) Math.round(Math.random()*10000);
|
||||
array[i] = (int) Math.round(Math.random() * 100);
|
||||
}
|
||||
|
||||
// Recorro e imprimo en pantalla
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
System.out.print(array[i] + " ");
|
||||
for (int n : array) {
|
||||
System.out.print(n + " ");
|
||||
}
|
||||
System.out.println("");
|
||||
|
||||
// Recorro para obtener la suma
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
suma += array[i];
|
||||
for (int n : array) {
|
||||
suma += n;
|
||||
}
|
||||
// Calculo la media
|
||||
media = suma / ((float) array.length);
|
||||
|
||||
15
src/tutorialJava/capitulo4_Arrays/EjemploMetodos.java
Normal file
15
src/tutorialJava/capitulo4_Arrays/EjemploMetodos.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package tutorialJava.capitulo4_Arrays;
|
||||
|
||||
import tutorialJava.UtilsArrays;
|
||||
|
||||
public class EjemploMetodos {
|
||||
|
||||
public static void main(String[] args) {
|
||||
int array[] = new int[10];
|
||||
UtilsArrays.inicializarArray(array, 10000);
|
||||
UtilsArrays.muestraArray(array);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user