-
Notifications
You must be signed in to change notification settings - Fork 349
Expand file tree
/
Copy pathLoops.java
More file actions
129 lines (99 loc) · 2.77 KB
/
Loops.java
File metadata and controls
129 lines (99 loc) · 2.77 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package basic.c06_loops;
/*
Clase 45 - Bucles
Vídeo: https://youtu.be/JOAqpdM36wI?t=15862
*/
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
public class Loops {
public static void main(String[] args) {
// Loops
/*
Clase 46 - for
Vídeo: https://youtu.be/JOAqpdM36wI?t=16003
*/
// - for controlado por contador
for (int index = 0; index < 5; index++) {
System.out.println("Hola, Java!");
}
String[] names = {"Brais", "Moure", "mouredev"};
for (int index = 0; index < names.length; index++) {
System.out.println(names[index]);
}
/*
Clase 47 - forEach
Vídeo: https://youtu.be/JOAqpdM36wI?t=16646
*/
// - for-each
for (String name: names) {
System.out.println(name);
}
HashSet<Integer> numbers = new HashSet<>();
numbers.add(1);
numbers.add(2);
numbers.add(3);
numbers.add(4);
numbers.add(5);
for (Integer number: numbers) {
System.out.println(number);
}
HashMap<String, String> emails = new HashMap<>();
emails.put("Brais", "brais@gmail.com");
emails.put("Moure", "moure@gmail.com");
emails.put("MoureDev", "mouredev@gmail.com");
for (Map.Entry<String, String> email: emails.entrySet()) {
System.out.println(email.getKey());
System.out.println(email.getValue());
}
/*
Clase 48 - while / do while
Vídeo: https://youtu.be/JOAqpdM36wI?t=17199
*/
// - while
int index = 0;
while (index < 5) {
System.out.println("Hola, Java!");
index++;
}
index = 0;
while (index < names.length) {
System.out.println(names[index]);
index++;
}
index = 0;
boolean find = false;
while (!find) {
System.out.println(names[index]);
if (names[index].equals("Moure")) {
find = true;
}
index++;
}
// - do-while
index = 0;
do {
System.out.println("Hola, Java!");
index++;
} while (index < 0);
/*
Clase 49 - Control de bucles
Vídeo: https://youtu.be/JOAqpdM36wI?t=17688
*/
// Control de bucles
// - break
for (String name: names) {
if (name.equals("Moure")) {
break;
}
System.out.println(name);
}
// - continue
for (int i = 0; i < 5; i++) {
if (i == 3) {
continue;
}
System.out.println(i);
}
}
}