Skip to content

Commit 2bc5b92

Browse files
committed
#2-Java
1 parent 607dfcc commit 2bc5b92

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
public class bladi23 {
2+
3+
// Variable global
4+
static int globalVar = 10;
5+
6+
// Función sin parámetros ni retorno
7+
static void printHello() {
8+
System.out.println("Hello, world!");
9+
}
10+
11+
// Función con un parámetro y sin retorno
12+
static void printNumber(int num) {
13+
System.out.println("Number: " + num);
14+
}
15+
16+
// Función con varios parámetros y sin retorno
17+
static void suma(int num1, int num2) {
18+
System.out.println("Sum: " + (num1 + num2));
19+
}
20+
21+
// Función con retorno
22+
static int conRetorno(int num) {
23+
return num * 2;
24+
}
25+
26+
// Función que utiliza una función ya creada en el lenguaje (Math.sqrt)
27+
static double getSquareRoot(int num) {
28+
return Math.sqrt(num);
29+
}
30+
31+
// Función que prueba el concepto de variable local y global
32+
static void variableLocalyGlobal() {
33+
int localVar = 5; // Variable local
34+
System.out.println("Global variable: " + globalVar);
35+
System.out.println("Local variable: " + localVar);
36+
}
37+
38+
static int extra(String str1, String str2) {
39+
int contador = 0;
40+
for (int i = 1; i <= 100; i++) {
41+
if (i % 3 == 0 && i % 5 == 0) {
42+
System.out.println(str1 + str2);
43+
} else if (i % 3 == 0) {
44+
System.out.println(str1);
45+
} else if (i % 5 == 0) {
46+
System.out.println(str2);
47+
} else {
48+
System.out.println(i);
49+
contador++;
50+
}
51+
}
52+
return contador;
53+
}
54+
55+
public static void main(String[] args) {
56+
printHello();
57+
printNumber(5);
58+
suma(3, 4);
59+
System.out.println("Double: " + conRetorno(7));
60+
System.out.println("Square root: " + getSquareRoot(9));
61+
variableLocalyGlobal();
62+
int count = extra("Fizz", "Buzz");
63+
System.out.println("Count: " + count);
64+
}
65+
}
66+

0 commit comments

Comments
 (0)