2 Star 0 Fork 0

热门极速下载/hello-java

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Loops.java 2.38 KB
一键复制 编辑 原始数据 按行查看 历史
Brais Moure 提交于 2个月前 . Clase 5 | 06/05/2025
package basic.c06_loops;
/*
Clase 5 - Bucles y funciones (06/05/2025)
Vídeo: https://www.twitch.tv/videos/2452053839
*/
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
public class Loops {
public static void main(String[] args) {
// Loops
// - 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]);
}
// - 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());
}
// - 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);
// 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);
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_trending/hello-java.git
git@gitee.com:mirrors_trending/hello-java.git
mirrors_trending
hello-java
hello-java
main

搜索帮助