Skip to content

Commit 2ef2b7e

Browse files
authored
Merge pull request mouredev#3324 from adrs1166ma/main
#00 - Java
2 parents 1cbee08 + 6f860f9 commit 2ef2b7e

File tree

2 files changed

+221
-0
lines changed

2 files changed

+221
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
public class adrs1166ma {
2+
public static void main(String[] args) {
3+
// URL del sitio oficial Java: https://www.java.com/
4+
5+
// - - - Tipos de comentario - - -
6+
7+
// Una linea 1
8+
9+
/* Una linea 2 */
10+
11+
/*
12+
* Varias
13+
* lineas 1
14+
*/
15+
16+
/*
17+
Varias
18+
lineas 2
19+
*/
20+
21+
// -- -- Variables y Constantes -- --
22+
String miVariable = "Soy una variable";
23+
final String miConstante = "Soy una constante";
24+
25+
// -- -- Tipos de datos primitivos -- --
26+
// Caja[tipo] = Numero Maximo
27+
28+
/* Primitivos Enteros */
29+
byte datoByte = 127;
30+
short datoShort = 32767;
31+
int datoInt = 2147483647;
32+
33+
/* Primitivos Flotantes */
34+
long datoLong = 9223372036854775807L; // L al final
35+
float datoFloat = 3.4028235E38F; // F al final
36+
double datoDouble = 1.7976931348623157E308;
37+
38+
/* Primitivos Character */
39+
char datoCharSimbolo = 'a';
40+
char datoCharDecimal = 80;
41+
42+
/* Primitivos Booleano */
43+
boolean datoBoolean1 = true;
44+
boolean datoBoolean2 = false;
45+
46+
String saludo = "¡Hola";
47+
final String lenguaje = "Java";
48+
System.out.println(saludo + ", " + lenguaje + "!");
49+
50+
}
51+
52+
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
public class adrs1166ma {
2+
public static void main(String[] args) {
3+
// Operando1 = a
4+
// Operando2 = b
5+
// Respuesta = r
6+
int a = 5, b = 3, r = 0;
7+
System.out.println("Numero 1: "+a+" | Numero 2:"+b);
8+
9+
// ----------------------------------------------
10+
System.out.println("/* -- Aritmeticos -- */");
11+
System.out.println("Suma: "+(a+b));
12+
System.out.println("Resta: "+(a-b));
13+
System.out.println("Multiplicacion: "+(a*b));
14+
System.out.println("Division: "+(a/b));
15+
System.out.println("Residuo: "+(a%b));
16+
17+
// ----------------------------------------------
18+
System.out.println("/* -- Logicos -- */");
19+
boolean t = true;
20+
boolean f = false;
21+
System.out.println(" -- Y [AND] -- ");
22+
System.out.println("false && false = " + (f && f));
23+
System.out.println("false && true = " + (f && t));
24+
System.out.println("true && false = " + (t && f));
25+
System.out.println("true && true = " + (t && t));
26+
27+
System.out.println(" -- O [OR] -- ");
28+
System.out.println("false || false = " + (f || f));
29+
System.out.println("false || true = " + (f || t));
30+
System.out.println("true || false = " + (t || f));
31+
System.out.println("true || true = " + (t || t));
32+
33+
System.out.println(" -- Negacion [NOT] -- ");
34+
System.out.println("!true = " + (!t));
35+
System.out.println("!false = " + (!f));
36+
37+
// ----------------------------------------------
38+
System.out.println("/* -- Comparacion -- */");
39+
System.out.println("a == b = " + (a == b));
40+
System.out.println("a != b = " + (a != b));
41+
System.out.println("a > b = " + (a > b));
42+
System.out.println("a < b = " + (a < b));
43+
System.out.println("a >= b = " + (a >= b));
44+
System.out.println("a <= b = " + (a <= b));
45+
46+
47+
// ----------------------------------------------
48+
System.out.println(" -- Asignacion -- ");
49+
System.out.println("Asignación: " + (a = b));
50+
System.out.println("Suma y asignación: " + (a += b));
51+
System.out.println("Resta y asignación: " + (a -= b));
52+
System.out.println("Multiplicación y asignación: " + (a *= b));
53+
System.out.println("División y asignación: " + (a /= b));
54+
System.out.println("Resto y asignación: " + (a %= b));
55+
System.out.println("AND y asignación: " + (a &= b));
56+
System.out.println("OR y asignación: " + (a |= b));
57+
System.out.println("XOR y asignación: " + (a ^= b));
58+
System.out.println("Desplazamiento a la izquierda y asignación: " + (a <<= b));
59+
System.out.println("Desplazamiento a la derecha y asignación: " + (a >>= b));
60+
System.out.println("Desplazamiento a la derecha sin signo y asignación: " + (a >>>= b));
61+
62+
// ----------------------------------------------
63+
64+
/* NO IDENTIDAD | NO PERTENCIA */
65+
66+
// ----------------------------------------------
67+
68+
System.out.println(" -- Bits -- ");
69+
System.out.println("5 & 2 = " + (a & b));
70+
System.out.println("5 | 2 = " + (a | b));
71+
System.out.println("5 ^ 2 = " + (a ^ b));
72+
System.out.println("~5 = " + (~a));
73+
System.out.println("5 << 2 = " + (a << 2));
74+
System.out.println("5 >> 2 = " + (a >> 2));
75+
System.out.println("5 >>> 2 = " + (a >>> 2));
76+
77+
// ----------------------------------------------
78+
79+
/*
80+
* Estructuras de control
81+
*/
82+
83+
System.out.println(" -- Ternarios -- ");
84+
int mayorEdad = 18;
85+
String msg = mayorEdad >= 18 ? "Eres mayor de edad" : "Eres menor de Edad";
86+
System.out.println(msg);
87+
88+
System.out.println(" -- if | else -- ");
89+
boolean miCondicion = false;
90+
if (miCondicion == true) {
91+
System.out.println(" Mi condición es verdadera ");
92+
} else if (miCondicion == false) {
93+
System.out.println(" Mi condicion es reconocida ");
94+
} else {
95+
System.out.println(" Mi condicion es reconocida ");
96+
}
97+
98+
System.out.println(" -- for -- ");
99+
for (int i = 0; i < 10; i++){
100+
System.out.println("i = "+i);
101+
}
102+
103+
int i = 0;
104+
System.out.println(" -- while -- ");
105+
while (i < 10){
106+
System.out.println("i = "+i);
107+
i++;
108+
}
109+
110+
System.out.println(" -- do while -- ");
111+
do {
112+
System.out.println("i = "+i);
113+
i++;
114+
} while (i < 5);
115+
116+
System.out.println(" -- switch -- ");
117+
switch (a) {
118+
case 1:
119+
System.out.println("a es 1");
120+
break;
121+
case 2:
122+
System.out.println("a es 2");
123+
break;
124+
case 3:
125+
System.out.println("a es 3");
126+
break;
127+
default:
128+
System.out.println("a no es 1, 2 o 3");
129+
break;
130+
}
131+
132+
System.out.println(" -- break -- ");
133+
for (int j=0;j<5;j++){
134+
if (j==3){
135+
break;
136+
}
137+
System.out.println("j = "+j);
138+
}
139+
140+
System.out.println(" -- continue -- ");
141+
for (int j=0;j<5;j++){
142+
if (j==3){
143+
continue;
144+
}
145+
System.out.println("j = "+j);
146+
}
147+
148+
try {
149+
int resultado = a/0;
150+
System.out.println("Resultado: "+resultado);
151+
} catch (ArithmeticException e){
152+
System.out.println("Error: Division por cero");
153+
}
154+
155+
/*
156+
* Extra
157+
*/
158+
159+
for (int x=10;x<=55;x++){
160+
if (x==16){
161+
continue;
162+
} else if ((x%3)==0) {
163+
continue;
164+
} else {
165+
System.out.println(x);
166+
}
167+
}
168+
}
169+
}

0 commit comments

Comments
 (0)