Skip to content

Commit ee6f751

Browse files
authored
Merge pull request #577 from alvarofernandezavalos/main
#2 - Java
2 parents 37153f6 + 01b485b commit ee6f751

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
public class alvarofernandezavalos {
2+
3+
public static int globalInt = 10;
4+
5+
public static void main(String[] args) {
6+
funcionSinParametrosNiRetorno();
7+
System.out.println(funcionSinParametrosConRetorno());
8+
funcionConParemetroSinRetorno("alvarofernandezavalos");
9+
System.out.println(funcionConParametroConRetorno("alvarofernandezavalos"));
10+
System.out.println(funcionConDosParametrosConRetorno("alvarofernandez", "avalos"));
11+
System.out.println(funcionConNParametrosConRetorno(1,2,3,4,5,6,10));
12+
System.out.println("Java Home: "+getJavaHome());
13+
System.err.println("Operating System: "+getOS());
14+
variableGlobalyLocal();
15+
System.out.println("La función retorna el número de veces que se ha impreso el número en lugar de los textos: " + opcional("tortuga","grande"));
16+
}
17+
18+
private static int opcional(String a, String b) {
19+
int numero=0;
20+
for(int i = 1; i <= 100 ; i++) {
21+
if (i%3==0) System.out.println(a);
22+
if (i%5==0) System.out.println(b);
23+
if (i%3==0 && i%5==0) System.out.println(a.concat(b));
24+
if (i%3!=0 && i%5!=0) {
25+
numero++;
26+
System.out.println(i);
27+
}
28+
}
29+
return numero;
30+
}
31+
32+
private static void variableGlobalyLocal() {
33+
int globalInt;
34+
globalInt = 100;
35+
System.out.println("La variable local globalInt en esta funcion vale: " + globalInt);
36+
System.out.println("La variable global globalInt vale: " + alvarofernandezavalos.globalInt);
37+
}
38+
39+
public static void funcionSinParametrosNiRetorno() {
40+
System.out.println("funcionSinParametrosNiRetorno");
41+
}
42+
43+
public static String funcionSinParametrosConRetorno() {
44+
return "retorno";
45+
}
46+
47+
public static void funcionConParemetroSinRetorno(String texto) {
48+
System.out.println("Parametro 1: "+texto);
49+
}
50+
51+
public static String funcionConParametroConRetorno(String texto) {
52+
return texto;
53+
}
54+
55+
public static String funcionConDosParametrosConRetorno(String texto, String texto2) {
56+
return texto.concat(texto2);
57+
}
58+
59+
public static int funcionConNParametrosConRetorno (int ... numeros) {
60+
int suma = 0;
61+
for (int i : numeros) {
62+
suma += i;
63+
}
64+
return suma;
65+
}
66+
67+
public static String getJavaHome() {
68+
return System.getProperty("java.home");
69+
}
70+
71+
public static String getOS() {
72+
return System.getProperty("os.name");
73+
}
74+
75+
}

0 commit comments

Comments
 (0)