Skip to content

Commit 7a3b175

Browse files
authored
Merge pull request mouredev#7066 from JulianJRA/main
#00 - Java
2 parents 7554cf6 + 7ff43bc commit 7a3b175

File tree

2 files changed

+200
-0
lines changed

2 files changed

+200
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
//Url de Java oficial: https://www.java.com/es/
3+
4+
//Comentario en linea
5+
6+
/*
7+
* Comentario en
8+
* varias lineas
9+
*/
10+
11+
public class JulianJRA {
12+
13+
public static void main(String[] args) {
14+
15+
//Variable en java
16+
String miVariable = "mi variable";
17+
18+
//Constante en java
19+
final String MI_CONSTANTE = "mi constante";
20+
21+
// Tipos de datos primitivos en java
22+
byte b = 127;
23+
short s = 32000;
24+
int i = 100000;
25+
long l = 10000000000L;
26+
27+
float f = 3.14f;
28+
double d = 3.14159265359;
29+
30+
char c = 'A';
31+
String st = "Hola";
32+
boolean bool = true;
33+
34+
//Imprimir por terminal
35+
System.out.println("¡Hola, Java!");
36+
37+
}
38+
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
2+
public class JulianJRA {
3+
4+
public static void main(String[] args) {
5+
6+
// Operadores aritméticos
7+
int a = 10, b = 3;
8+
9+
System.out.println("Suma: " + (a + b)); // 13
10+
System.out.println("Resta: " + (a - b)); // 7
11+
System.out.println("Multiplicación: " + (a * b)); // 30
12+
System.out.println("División: " + (a / b)); // 3 (división entera)
13+
System.out.println("Módulo: " + (a % b)); // 1 (resto)
14+
System.out.println("Incremento: " + (++a)); // 11 (preincremento)
15+
System.out.println("Decremento: " + (--b)); // 2 (predecremento)
16+
17+
// Operadores lógicos
18+
boolean x = true, y = false;
19+
20+
System.out.println("AND (&&): " + (x && y)); // false
21+
System.out.println("OR (||): " + (x || y)); // true
22+
System.out.println("NOT (!): " + (!x)); // false
23+
24+
// Operadores de comparación
25+
System.out.println("Igual a: " + (a == b)); // false
26+
System.out.println("No igual: " + (a != b)); // true
27+
System.out.println("Mayor que: " + (a > b)); // true
28+
System.out.println("Menor que: " + (a < b)); // false
29+
System.out.println("Mayor o igual: " + (a >= b)); // false
30+
System.out.println("Menor o igual: " + (a <= b)); // false
31+
32+
// Operadores de asignación
33+
a += 5; // a = a + 5
34+
System.out.println("Suma y asigna: " + a); // 15
35+
36+
a -= 3; // a = a - 3
37+
System.out.println("Resta y asigna: " + a); // 12
38+
39+
a *= 2; // a = a * 2
40+
System.out.println("Multiplica y asigna: " + a); // 24
41+
42+
a /= 4; // a = a / 4
43+
System.out.println("Divide y asigna: " + a); // 6
44+
45+
a %= 5; // a = a % 5
46+
System.out.println("Módulo y asigna: " + a); // 1
47+
48+
// Operadores a nivel de bits
49+
int c = 5; // 0101 en binario
50+
int d = 3; // 0011 en binario
51+
52+
System.out.println("AND (&): " + (c & d)); // 1 (0001 en binario)
53+
System.out.println("OR (|): " + (c | d)); // 7 (0111 en binario)
54+
System.out.println("XOR (^): " + (c ^ d)); // 6 (0110 en binario)
55+
System.out.println("NOT (~): " + (~c)); // -6 (inversión de bits)
56+
System.out.println("Shift izquierda (<<): " + (c << 1)); // 10 (1010 en binario)
57+
System.out.println("Shift derecha (>>): " + (c >> 1)); // 2 (0010 en binario)
58+
System.out.println("Shift derecha sin signo (>>>): " + (c >>> 1)); // 2
59+
60+
// ESTRUCTURAS CONDICIONALES
61+
// if-else
62+
int edad = 20;
63+
64+
if (edad >= 18) {
65+
System.out.println("Eres mayor de edad.");
66+
} else {
67+
System.out.println("Eres menor de edad.");
68+
}
69+
70+
// if-elseif-else
71+
int calificacion = 85;
72+
73+
if (calificacion >= 90) {
74+
System.out.println("Excelente");
75+
} else if (calificacion >= 70) {
76+
System.out.println("Aprobado");
77+
} else {
78+
System.out.println("Suspenso");
79+
}
80+
81+
// Switch
82+
int dia = 3;
83+
84+
switch (dia) {
85+
case 1:
86+
System.out.println("Lunes");
87+
break;
88+
case 2:
89+
System.out.println("Martes");
90+
break;
91+
case 3:
92+
System.out.println("Miércoles");
93+
break;
94+
default:
95+
System.out.println("Día no válido");
96+
}
97+
98+
// ESTRUCTURAS ITERATIVAS
99+
// for
100+
for (int i = 1; i <= 5; i++) {
101+
System.out.println("Iteración: " + i);
102+
}
103+
104+
// while
105+
int contador = 0;
106+
107+
while (contador < 3) {
108+
System.out.println("Contador: " + contador);
109+
contador++;
110+
}
111+
112+
// do-while
113+
int numero = 0;
114+
115+
do {
116+
System.out.println("Número: " + numero);
117+
numero++;
118+
} while (numero < 3);
119+
120+
// for-each
121+
int[] numeros = { 1, 2, 3, 4, 5 };
122+
123+
for (int num : numeros) {
124+
System.out.println("Número: " + num);
125+
}
126+
127+
// ESTRUCTURAS DE EXCEPCIONES
128+
// try-catch-finally
129+
try {
130+
int resultado = 10 / 0; // Genera una excepción (división por cero)
131+
System.out.println("Resultado: " + resultado);
132+
} catch (ArithmeticException e) {
133+
System.out.println("Error: División por cero no permitida.");
134+
} finally {
135+
System.out.println("Bloque 'finally' siempre se ejecuta.");
136+
}
137+
138+
// throw y throws
139+
try {
140+
dividir(10, 0);
141+
} catch (ArithmeticException e) {
142+
System.out.println("Error: " + e.getMessage());
143+
}
144+
145+
// EJERCICIO OPCIONAL
146+
for(int i = 10; i < 56; i++){
147+
if((i%2==0) && (i!=16) && (i%3!=0)){
148+
System.out.println("Numero ejercicio: "+i);
149+
}
150+
}
151+
152+
}
153+
154+
public static void dividir(int a, int b) throws ArithmeticException {
155+
if (b == 0) {
156+
throw new ArithmeticException("División por cero no permitida.");
157+
}
158+
System.out.println("Resultado: " + (a / b));
159+
}
160+
161+
}

0 commit comments

Comments
 (0)