Skip to content

Commit e9c154f

Browse files
committed
#1 - Java
1 parent d71a765 commit e9c154f

File tree

1 file changed

+200
-0
lines changed
  • Roadmap/01 - OPERADORES Y ESTRUCTURAS DE CONTROL/java

1 file changed

+200
-0
lines changed
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/** #01 - Java -> h4ckxel */
2+
3+
public class h4ckxel {
4+
public static void main(String[] args) {
5+
System.out.println("---EJERCIÓ---\n");
6+
/*
7+
* ARITMÉTICAS
8+
* Se utilizan para realizar cálculos matemáticos.
9+
*/
10+
11+
int a = 10;
12+
int b = 5;
13+
14+
System.out.println("---Operaciones Aritméticas---\n");
15+
16+
System.out.println("a:" + a);
17+
System.out.println("b:" + b);
18+
System.out.println("\nSuma: a + b = " + (a + b)); // Suma
19+
System.out.println("Resta: a - b = " + (a - b)); // Resta
20+
System.out.println("Multiplicar: a * b = " + (a * b)); // Multiplicar
21+
System.out.println("Exponente a ^ b" + (a ^ b));
22+
System.out.println("Division: a / b = " + (a / b)); // Division
23+
System.out.println("Modulo: a % b =" + (a % b)); // Modulo
24+
25+
/*
26+
* ASIGNACIONES
27+
* Se utilizan para asignar valores a las variables.
28+
*/
29+
30+
System.out.println("\n---Operaciones Asignación---\n");
31+
32+
int c = 10; // Asignación simple
33+
c += 5; // Suma y asigna
34+
c -= 3; // Resta y asigna
35+
c *= 2; // Multiplica y asigna
36+
c /= 4; // Divide y asigna
37+
c %= 3; // Calcula el modulo y asigna
38+
System.err.println("Asignación simple: c = 5 - 10");
39+
System.err.println("Suma y asigna: c += 5 - 15");
40+
System.err.println("Suma y asigna: c -= 3 - 12");
41+
System.err.println("Suma y asigna: c *= 2 - 24");
42+
System.err.println("Suma y asigna: c /= 4 - 6");
43+
System.err.println("Suma y asigna: c %= 3 - 0");
44+
System.out.println("Resultado de Agnación: " + c);
45+
46+
/*
47+
* RELACIONALES
48+
* Se utilizan para comparar dos valores.
49+
*/
50+
51+
System.out.println("\n---Operaciones Relacional---\n");
52+
53+
int x = 10;
54+
int y = 20;
55+
56+
System.out.println("Es Igual: x == y - " + (x == y));
57+
System.out.println("Es Diferente: x != y - " + (x != y));
58+
System.out.println("Es Mayor: x > y - " + (x > y));
59+
System.out.println("Es Menor: x < y - " + (x < y));
60+
System.out.println("Es Mayor o Igual: x >= y - " + (x >= y));
61+
System.out.println("Es Menor o Igual: x <= y - " + (x <= y));
62+
63+
/*
64+
* LÓGICOS
65+
* Se utilizan para combinar expresiones booleanas.
66+
*/
67+
68+
System.out.println("\n---Operaciones Lógicos---\n");
69+
70+
boolean i = true;
71+
boolean k = false;
72+
73+
System.out.println("Operador i && k: " + (i && k));
74+
System.out.println("Operador i || k: " + (i || k));
75+
System.out.println("Operador !k: " + (!k));
76+
77+
/*
78+
* UNARIAS
79+
* Se aplican a un solo operando.
80+
*/
81+
82+
System.out.println("\n---Operaciones Unarias---\n");
83+
84+
int d = 5;
85+
System.out.println("Incremento: " + d++);
86+
System.out.println("Decremento: " + d--);
87+
System.out.println("Negativo: " + (-d));
88+
System.out.println("Positivo: " + (+d));
89+
90+
/*
91+
* BIT A BIT
92+
* Se utilizan para realizar operaciones a nivel de bits.
93+
*/
94+
95+
System.out.println("\n---Operaciones Unarias---\n");
96+
97+
int e = 6;
98+
int f = 3;
99+
System.out.println("AND bir a bit: e & f - " + (e & f));
100+
System.out.println("OR bir a bit: e | f - " + (e | f));
101+
System.out.println("XOR bir a bit: e ^ f - " + (e ^ f));
102+
System.out.println("Complemento bir a bit: ~e - " + (~e));
103+
System.out.println("Desplazamiento a la izquierda: e << f - " + (e << f));
104+
System.out.println("Desplazamiento a la derecha: e >> f - " + (e >> f));
105+
System.out.println("Desplazamiento a la derecha sin singo: e >>> f - " + (e >>> f));
106+
107+
108+
/*
109+
* Estructuras de controles
110+
*/
111+
112+
/*
113+
* IF - ELSE If - ELSE
114+
*/
115+
System.out.println("\n---Estructuras de controles---\n");
116+
117+
System.out.println("\nSentiría IF-ELSE IF-ELSE");
118+
int num = 10;
119+
if (num > 0) {
120+
System.out.println("El número es Positivo");
121+
} else if (num < 0) {
122+
System.out.println("El número es Negativo");
123+
} else {
124+
System.out.println("El número es Cero");
125+
}
126+
127+
/*
128+
* SWITCH
129+
*/
130+
System.out.println("\nSentiría SWITCH");
131+
int day = 3;
132+
switch (day) {
133+
case 1:
134+
System.out.println("Lunes");
135+
break;
136+
case 2:
137+
System.out.println("Martes");
138+
break;
139+
case 3:
140+
System.out.println("Miércoles");
141+
break;
142+
default:
143+
System.out.println("Otro dia");
144+
break;
145+
}
146+
147+
/*
148+
* FOR
149+
*/
150+
System.out.println("\nBucle FOR");
151+
for (int j = 0; j < 5; j++) {
152+
System.out.println("Iteración: " + j);
153+
}
154+
155+
/*
156+
* WHILE
157+
*/
158+
System.out.println("\nBucle WHILE");
159+
int g = 0;
160+
while (g < 5) {
161+
System.out.println("Iteración: " + g);
162+
g++;
163+
}
164+
165+
/*
166+
* DO-WHILE
167+
*/
168+
System.out.println("\nBucle DO-WHILE");
169+
int l = 0;
170+
do {
171+
System.out.println("Iteración: " + l);
172+
l++;
173+
} while (l < 5);
174+
175+
/*
176+
* TRY-CATCH-FINALLY
177+
*/
178+
System.out.println("\nBucle TRY-CATCH-FINALLY");
179+
try {
180+
int division = 10 / 0;
181+
System.out.println(division);
182+
} catch (ArithmeticException error) {
183+
System.out.println("Error: Division por cero");
184+
} finally{
185+
System.out.println("Este bloque se ejecuta siempre");
186+
}
187+
188+
/**-----DIFICULTAD EXTRA-----*/
189+
190+
System.out.println("\n-----EXTRA-----\n");
191+
192+
for(int m = 10; m < 55; m++){
193+
if ((m % 2 == 0) && (m != 16) && (m % 3 == 0)) {
194+
System.out.println(m);
195+
}
196+
}
197+
198+
/**-----DIFICULTAD EXTRA-----*/
199+
}
200+
}

0 commit comments

Comments
 (0)