From 5077b507166fa4819514901c1db8a85dc3f8533d Mon Sep 17 00:00:00 2001 From: huevo-dev Date: Wed, 15 Oct 2025 17:28:36 -0600 Subject: [PATCH] Completed: C05 - StructuresExercises. --- .idea/.gitignore | 3 ++ .idea/misc.xml | 6 +++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ MoureDev.iml | 11 +++++ basic/c05_structures/StructuresExercises.java | 47 +++++++++++++++++++ 6 files changed, 81 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 MoureDev.iml diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..188022c --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..9f26f60 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/MoureDev.iml b/MoureDev.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/MoureDev.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/basic/c05_structures/StructuresExercises.java b/basic/c05_structures/StructuresExercises.java index c60b52e..3ad5fa7 100644 --- a/basic/c05_structures/StructuresExercises.java +++ b/basic/c05_structures/StructuresExercises.java @@ -5,28 +5,75 @@ Vídeo: https://youtu.be/JOAqpdM36wI?t=15680 */ +import java.util.*; +import java.util.Arrays; + +import static java.lang.IO.println; + public class StructuresExercises { public static void main(String[] args) { // 1. Crea un Array con 5 valores e imprime su longitud. + String[] colors = {"red", "blue", "yellow", "orange", "purple", "white"}; + println("Colors length: " + colors.length); + // 2. Modifica uno de los valores del Array e imprime el valor del índice antes y después de modificarlo. + println("Before modify color: " + colors[2]); + colors[2] = "black"; + println("After modify color: " + colors[2]); + // 3. Crea un ArrayList vacío. + ArrayList numbers = new ArrayList<>(); + // 4. Añade 4 valores al ArrayList y elimina uno a continuación. + numbers.add(1); + numbers.add(2); + numbers.add(3); + numbers.add(4); + + numbers.remove(2); + // 5. Crea un HashSet con 2 valores diferentes. + HashSet identifiers = new HashSet<>(); + identifiers.add("123"); + identifiers.add("456"); + // 6. Añade un nuevo valor repetido y otro sin repetir al HashSet. + identifiers.add("123"); + identifiers.add("789"); + // 7. Elimina uno de los elementos del HashSet. + identifiers.remove("789"); + // 8. Crea un HashMap donde la clave sea un nombre y el valor el número de teléfono. Añade tres contactos. + HashMap contacts = new HashMap<>(); + contacts.put("Javier", 123); + contacts.put("Danni", 456); + contacts.put("Bry", 789); + // 9. Modifica uno de los contactos y elimina otro. + contacts.replace("Danni", 159); + // 10. Dado un Array, transfórmalo en un ArrayList, a continuación en un HashSet y finalmente en un HashMap con clave y valor iguales. + + ArrayList colorsList = new ArrayList<>(Arrays.asList(colors)); + HashSet colorsHashSet = new HashSet<>(Arrays.asList(colors)); + HashMap colorsHashMap = new HashMap<>(); + + for (int i = 0; i < colors.length; i++) { + colorsHashMap.putIfAbsent(colors[i], i); + println("Color ID: " + i + " || Color name: " + colors[i]); + } + } }