forked from P1-FemCoders-VLC/java-loops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForLoops.java
More file actions
64 lines (49 loc) · 1.92 KB
/
Copy pathForLoops.java
File metadata and controls
64 lines (49 loc) · 1.92 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
public class ForLoops {
public static void main(String[] args) {
//Escribe un bucle for que imprima números del 1 al 10
for (int i = 1; i <= 10; i++){
System.out.print(i + " ");
}
//Escribe un bucle for que imprima "¡Hola FemCoders!" 5 veces
for (int i = 0; i <= 5; i++){
System.out.println("¡Hello, FemCoders!");
}
//Escribe un bucle for que imprima la tabla de multiplicar del número 7 (del 1 al 10)
for (int i = 1; i <= 10; i++){
System.out.print(i * 7 + " ");
}
//Escribe un bucle for que imprima números del 10 al 1
for (int i = 10; i > 0; i--){
if(i == 10){System.out.println(i + " ");}
System.out.print(i + " ");
}
//Escribe un bucle for que imprima los 10 primeros números impares
int oddNum = 0;
for (int i = 1; oddNum <= 10; i++){
if(i%2 != 0) {
if (oddNum == 0) {
System.out.println(i + " ");
} else {
System.out.print(i + " ");
}
oddNum++;
}
}
System.out.println();
//Escribe un bucle for que encuentre el número más pequeño que sea mayor a 20 y que sea divisible para 8, usando 'break'.
//Imprime: El número más pequeño mayor de 20 que es divisible para 8 es <result>
for(int i = 20; i >= 1; i++){
if(i > 20 && (i%8 == 0)){
System.out.println("The smallest number greater than 20 that is divisible by 8 is " + i);
break;
}
}
//Escribe un bucle for que imprima números pares del 1 al 20 saltando los números impares usando 'continue'
for(int i = 1; i <= 20; i++){
if(i % 2 != 0){
continue;
}
System.out.print(i + " ");
}
}
}