Skip to content

Commit 8b91498

Browse files
committed
#1 - Java
1 parent b0d29ad commit 8b91498

File tree

1 file changed

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

1 file changed

+145
-0
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
public class Pbjmg {
2+
public static void main(String[] args){
3+
4+
// Operadores aritmeticos
5+
int suma = 24 + 5; //29
6+
double resta = 3.2 - 1.1; //2.1
7+
double division = 5 / 2; //2.5
8+
int modulo = 6 % 2; //0
9+
int multiplicacion = 10 * 2; //20
10+
11+
// Operadores logicos
12+
boolean andLogico = (5 > 3 && 8 > 4); //true
13+
boolean notLogico = !(8>2); //false
14+
15+
// Operadores de asignacion
16+
int x = 8; //8
17+
x += 2; //10
18+
x -= 5; //5
19+
x *= 4; //20
20+
x /= 2; //10
21+
x %= 2; //0
22+
23+
// Operadores de comparacion
24+
boolean esIgual = (5 == 5); //true
25+
boolean esDiferente = (5 != 3); //true
26+
boolean mayor = (4 > 2); //true
27+
boolean menor = (1 < 6); //true
28+
boolean mayorIgual = (9 >= 9); //true
29+
boolean menorIgual = (8<=8); //true
30+
31+
// Operadores de incremento y decremento
32+
int a = 5;
33+
a ++; //6
34+
int b = 4;
35+
b--; //3
36+
int preIncremento = ++a + --b; //9 (incrementa o decrece el valor antes de devolverlo)
37+
System.out.println(a);
38+
System.out.println(b);
39+
System.out.println(preIncremento);
40+
41+
// Operador ternario
42+
int edad = 38;
43+
String mensaje = (edad >= 25) ? "Viejo" : "Joven"; //Viejo
44+
System.out.println(mensaje);
45+
//------------------------------------------------
46+
47+
// Estructuras Condicionales
48+
//if-else
49+
edad = 18;
50+
if (edad>=18) {
51+
System.out.println("Eres mayor de edad");
52+
}else {
53+
System.out.println("Eres menor de edad");
54+
}
55+
56+
//if-else if-else
57+
int nota = 75;
58+
if(nota>=90) {
59+
System.out.println("Sobresaliente");
60+
}else if(nota>=70){
61+
System.out.println("Notable");
62+
}else {
63+
System.out.println("Aprobado");
64+
}
65+
66+
//Switch
67+
int dia = 5;
68+
String resultado = switch (dia) {
69+
case 1 -> "Lunes";
70+
case 2 -> "Martes";
71+
case 3 -> "Miercoles";
72+
case 4 -> "Jueves";
73+
case 5 -> "Viernes";
74+
case 6 -> "Sabado";
75+
case 7 -> "Domingo";
76+
default -> "No valido";
77+
};
78+
System.out.println(resultado);
79+
80+
//Estructuras repetitivas, Bucles
81+
//While
82+
int i = 0;
83+
while(i <= 5) {
84+
System.out.println(i);
85+
i++;
86+
}
87+
88+
//do-while
89+
int j = 0;
90+
do {
91+
System.out.println(j);
92+
j++;
93+
}while(j<=5);
94+
95+
//for
96+
for(int k = 0; k <=5; k++) {
97+
System.out.println("Iteracion: " + k);
98+
}
99+
100+
//for-each
101+
int[] lista = {1,2,3,4,5};
102+
for(int num : lista) {
103+
System.out.print(num);
104+
}
105+
106+
// Estructuras de control, interrupcion
107+
//break
108+
for(i = 0; i < 10; i++) {
109+
if(i == 5) {
110+
break; // Se detiene la iteracion en 5
111+
}
112+
System.out.println(i);
113+
}
114+
115+
//continue
116+
for(i = 0; i < 10; i++) {
117+
if(i == 5) {
118+
continue; // Se salta el numero 5
119+
}
120+
System.out.println(i);
121+
}
122+
123+
//return
124+
System.out.println(sumar(10,25));
125+
System.out.println();
126+
127+
//------------------ Opcional
128+
/*
129+
Imprimimos por pantalla los numeros comprendidos del 10 al 55 incluidos
130+
que sean pares, saltandonos el 16 y que no sean multiplos de 3
131+
*/
132+
for(i = 10; i <= 55; i++) {
133+
if(i%2==0 && i != 16 && i %3 != 0){
134+
System.out.println(i);
135+
}
136+
}
137+
138+
139+
}
140+
141+
//return
142+
public static int sumar (int num1,int num2) {
143+
return num1 + num2;
144+
}
145+
}

0 commit comments

Comments
 (0)