forked from mouredev/hello-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctions.java
More file actions
72 lines (49 loc) · 1.62 KB
/
Functions.java
File metadata and controls
72 lines (49 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package basic.c07_functions;
/*
Clase 5 - Bucles y funciones (06/05/2025)
Vídeo: https://www.twitch.tv/videos/2452053839
*/
import java.util.ArrayList;
import java.util.Arrays;
public class Functions {
public static void main(String[] args) {
// Funciones
for (int index = 0; index < 5; index++) {
sendEmail();
}
// ...
sendEmail();
sendEmailToUser("[email protected]");
sendEmailToUser(users);
System.out.println(state);
System.out.println(sendEmailWithState(""));
}
// Función sin parámetros ni retorno
public static void sendEmail() {
System.out.println("Se envía el email");
}
// Función con parámetros
public static void sendEmailToUser(String email) {
System.out.println("Se envía el email a " + email);
}
// Sobrecarga de funciones
public static void sendEmailToUser(String email, String name) {
System.out.println("Se envía el email a " + name + " (" + email + ")");
}
public static void sendEmailToUser(ArrayList<String> emails) {
for (String email: emails) {
sendEmailToUser(email);
}
}
// Función con retorno
public static boolean sendEmailWithState(String email) {
if (email.isEmpty()) {
return false;
}
System.out.println("Se envía el email a " + email);
return true;
}
}