Skip to content

Commit

Permalink
Merge pull request mouredev#1022 from bladi23/main
Browse files Browse the repository at this point in the history
#1 #2 #3 - Java
  • Loading branch information
Roswell468 committed Jan 21, 2024
2 parents 95a2ca5 + cd6b2ce commit e363a00
Show file tree
Hide file tree
Showing 3 changed files with 329 additions and 6 deletions.
124 changes: 118 additions & 6 deletions Roadmap/01 - OPERADORES Y ESTRUCTURAS DE CONTROL/java/bladi23.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,121 @@
public class bladi23 {
String hola = "hola";
int numero = 12;
//Hazme los constructures
public bladi23(String hola, int numero) {
this.hola = hola;
this.numero = numero;
public static void main(String[] args) {

// Tipos de operadores en java

// Operadores aritmeticos
int a = 2, b = 4;
System.out.println("a + b = " + (a + b));
System.out.println("a - b = " + (a - b));
System.out.println("a * b = " + (a * b));
System.out.println("b / a = " + (b / a));
System.out.println("b % a = " + (b % a));
System.out.println("a++ = " + (a++));
System.out.println("b-- = " + (b--));
// Operadores de asignacion
a += 2;
System.out.println("a += 2 = " + a);

// Operadores de comparacion
System.out.println("a == b: " + (a == b));
System.out.println("a != b: " + (a != b));
System.out.println("a > b: " + (a > b));
System.out.println("a < b: " + (a < b));
System.out.println("b >= a: " + (b >= a));
System.out.println("b <= a: " + (b <= a));
// Operadores logicos
System.out.println("(a == b) && (a < b): " + ((a == b) && (a < b)));
System.out.println("(a == b) || (a < b): " + ((a == b) || (a < b)));
System.out.println("!(a == b): " + !(a == b));

// Operadores de incremento y decremento
a++; // incremento
a--; // decremento

// Operadores de concatenacion
String texto1 = "Hola, ";
String texto2 = "¿cómo estás?";
System.out.println(texto1 + texto2);

// Operadores ternarios
String result = (a > b) ? "a es mayor que b" : "b es mayor o igual que a";
System.out.println(result);
// Operadores de instancia
String texto = "Hola";
if (texto instanceof String) {
System.out.println("texto es una instancia de String");
}

// Tipos de estructura de control en java

// Estructura if
if (a > b) {
} else if (a == b) {
} else {
System.out.println("a es menor que b");
}

// Estructura switch
switch (a) {
case 1:
System.out.println("a es igual a 1");
break;
case 2:
System.out.println("a es igual a 2");
break;
default:
System.out.println("a no es igual a 1 ni a 2");
break;
}

// Estructura while
while (a < b) {
System.out.println("a es menor que b");
a++;
}

// Estructura do while
do {
System.out.println("a es menor que b");
a++;
} while (a < b);

// Estructura for
for (int i = 0; i < 10; i++) {
System.out.println("i es igual a " + i);
}

// Estructura for each
int[] numeros = { 1, 2, 3, 4, 5 };
for (int numero : numeros) {
System.out.println("numero es igual a " + numero);
}

// Estructura break
for (int i = 0; i < 10; i++) {
if (i == 5) {
break;
}
System.out.println("i es igual a " + i);
}
// Estructura continue
for (int i = 0; i < 10; i++) {
if (i == 5) {
continue;
}
System.out.println("i es igual a " + i);
}

/*
* DIFICULTAD EXTRA (opcional):
* Crea un programa que imprima por consola todos los números comprendidos
* entre 10 y 55 (incluidos), pares, y que no son ni el 16 ni múltiplos de 3.
*/

for (int i = 10; i <= 55; i++) {
if (i % 2 == 0 && i != 16 && i % 3 != 0) {
System.out.println(i);
}
}
}
}
66 changes: 66 additions & 0 deletions Roadmap/02 - FUNCIONES Y ALCANCE/java/bladi23.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
public class bladi23 {

// Variable global
static int globalVar = 10;

// Función sin parámetros ni retorno
static void printHello() {
System.out.println("Hello, world!");
}

// Función con un parámetro y sin retorno
static void printNumber(int num) {
System.out.println("Number: " + num);
}

// Función con varios parámetros y sin retorno
static void suma(int num1, int num2) {
System.out.println("Sum: " + (num1 + num2));
}

// Función con retorno
static int conRetorno(int num) {
return num * 2;
}

// Función que utiliza una función ya creada en el lenguaje (Math.sqrt)
static double getSquareRoot(int num) {
return Math.sqrt(num);
}

// Función que prueba el concepto de variable local y global
static void variableLocalyGlobal() {
int localVar = 5; // Variable local
System.out.println("Global variable: " + globalVar);
System.out.println("Local variable: " + localVar);
}

static int extra(String str1, String str2) {
int contador = 0;
for (int i = 1; i <= 100; i++) {
if (i % 3 == 0 && i % 5 == 0) {
System.out.println(str1 + str2);
} else if (i % 3 == 0) {
System.out.println(str1);
} else if (i % 5 == 0) {
System.out.println(str2);
} else {
System.out.println(i);
contador++;
}
}
return contador;
}

public static void main(String[] args) {
printHello();
printNumber(5);
suma(3, 4);
System.out.println("Double: " + conRetorno(7));
System.out.println("Square root: " + getSquareRoot(9));
variableLocalyGlobal();
int count = extra("Fizz", "Buzz");
System.out.println("Count: " + count);
}
}

145 changes: 145 additions & 0 deletions Roadmap/03 - ESTRUCTURAS DE DATOS/java/bladi23.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Scanner;

public class bladi23 {
static Scanner sc = new Scanner(System.in);
static ArrayList<bladi23> arrayList = new ArrayList<bladi23>();
String nombre;
int numero;

public bladi23(String nombre, int numero) {
this.nombre = nombre;
this.numero = 0;
}

public String getNombre() {
return nombre;
}

public int getNumero() {
return 0;
}

public void setNombre(String nombre) {
this.nombre = nombre;
}

public void setNumero(int numero) {
this.numero = 0;
}

public static void main(String[] args) {
// Ejemplo de lista
int[] array = new int[5];
array[0] = 1; // Insercion
array[1] = 2; // Insercion
array[0] = 0; // Actualizacion
Arrays.sort(array); // Ordenacion

// Ejemplo de arraylist
ArrayList<Integer> lista = new ArrayList<>();
lista.add(1); // Insercion
lista.add(2); // Insercion
lista.remove(0); // Borrado
Collections.sort(lista); // Ordenacion

// Ejemplo de set
HashSet<Integer> conjunto = new HashSet<>();
conjunto.add(1); // Insercion
conjunto.remove(1); // Borrado
conjunto.add(2); // Para actualizar, se debe eliminar y luego agregar el nuevo

// Ejemplo de mapa
Map<String, String> mapa = new HashMap<>();
mapa.put("clave1", "valor1"); // Inserción
mapa.put("clave2", "valor2");
mapa.remove("clave1"); // Borrado
mapa.put("clave2", "valor3"); // Actualización

// Agenda
boolean salir = false;
while (!salir) {
System.out.println("1. Agregar contacto");
System.out.println("2. Busqueda de contacto");
System.out.println("3. Insertar contacto");
System.out.println("4. Actualizar contacto");
System.out.println("5. Eliminar contacto");
System.out.println("6. Salir");
String op = sc.nextLine();
switch (op) {
case "1":
agregarContacto();
break;
case "2":
buscarContacto();
break;
case "3":
insertarContacto();
break;
case "4":
actualizarContacto();
break;
case "5":
eliminarContacto();
break;
case "6":
salir = true;
break;
}
}

}

static void agregarContacto() {
System.out.println("Ingrese el nombre del contacto");
String nombre = sc.nextLine();
System.out.println("Ingrese el numero del contacto");
int numero = sc.nextInt();
bladi23 contacto = new bladi23(nombre, numero);
arrayList.add(contacto);
}

static void buscarContacto() {
System.out.println("Ingrese el nombre del contacto");
String nombre = sc.nextLine();
for (int i = 0; i < arrayList.size(); i++) {
if (arrayList.get(i).getNombre().equals(nombre)) {
System.out.println("El numero de " + nombre + " es " + arrayList.get(i).getNumero());
}
}
}

static void insertarContacto() {
System.out.println("Ingrese el nombre del contacto");
String nombre = sc.nextLine();
System.out.println("Ingrese el numero del contacto");
int numero = sc.nextInt();
bladi23 contacto = new bladi23(nombre, numero);
arrayList.add(contacto);
}

static void actualizarContacto() {
System.out.println("Ingrese el nombre del contacto");
String nombre = sc.nextLine();
System.out.println("Ingrese el numero del contacto");
int numero = sc.nextInt();
bladi23 contacto = new bladi23(nombre, numero);
arrayList.add(contacto);
}

static void eliminarContacto() {
System.out.println("Ingrese el nombre del contacto");
String nombre = sc.nextLine();
for (int i = 0; i < arrayList.size(); i++) {
if (arrayList.get(i).getNombre().equals(nombre)) {
arrayList.remove(i);
}
}
}

}

0 comments on commit e363a00

Please sign in to comment.