File tree 1 file changed +62
-0
lines changed
Roadmap/17 - ITERACIONES/java 1 file changed +62
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .ArrayList ;
2
+ import java .util .Collection ;
3
+
4
+ public class Josegs95 {
5
+ public static void main (String [] args ) {
6
+ //Ejercicio
7
+ //iterateFor(1, 10);
8
+ //iterateWhile(1, 10);
9
+ //iterateDoWhile(1, 10);
10
+
11
+ //Reto
12
+ retoFinal ();
13
+ }
14
+
15
+ public static void retoFinal (){
16
+ //Los 3 anteriores
17
+ //iterateRecursive(1, 10);
18
+ iterateForEach (createIntegerList (1 , 10 ));
19
+ }
20
+
21
+ public static void iterateFor (int begin , int end ){
22
+ for (;begin <= end ; begin ++){
23
+ System .out .println (begin );
24
+ }
25
+ }
26
+
27
+ public static void iterateWhile (int begin , int end ){
28
+ while (begin <= end ){
29
+ System .out .println (begin );
30
+ begin ++;
31
+ }
32
+ }
33
+
34
+ public static void iterateDoWhile (int begin , int end ){
35
+ do {
36
+ System .out .println (begin );
37
+ begin ++;
38
+ }while (begin <= end );
39
+ }
40
+
41
+ public static void iterateRecursive (int begin , int end ){
42
+ if (begin < end )
43
+ iterateRecursive (begin , end - 1 );
44
+ System .out .println (end );
45
+ }
46
+
47
+ public static void iterateForEach (Collection <Integer > intList ){
48
+ for (int n : intList ){
49
+ System .out .println (n );
50
+ }
51
+ }
52
+
53
+ private static ArrayList <Integer > createIntegerList (int begin , int end ){
54
+ ArrayList <Integer > intList = new ArrayList <>();
55
+ while (begin <= end ){
56
+ intList .add (begin );
57
+ begin ++;
58
+ }
59
+
60
+ return intList ;
61
+ }
62
+ }
You can’t perform that action at this time.
0 commit comments