|
@@ -12,6 +12,7 @@ public class PersonHandler {
|
12
|
12
|
|
13
|
13
|
public String whileLoop() {
|
14
|
14
|
String result = "";
|
|
15
|
+
|
15
|
16
|
// assume there is a `counter`
|
16
|
17
|
// while `counter` is less than length of array
|
17
|
18
|
// begin loop
|
|
@@ -21,6 +22,16 @@ public class PersonHandler {
|
21
|
22
|
// append `stringRepresentation` to `result` variable
|
22
|
23
|
|
23
|
24
|
// end loop
|
|
25
|
+
|
|
26
|
+ int counter = 0;
|
|
27
|
+
|
|
28
|
+ while (counter < personArray.length) {
|
|
29
|
+ Person currentPerson = personArray[counter];
|
|
30
|
+ String stringRepresentation = currentPerson.toString();
|
|
31
|
+ result = result.concat(stringRepresentation);
|
|
32
|
+ counter++;
|
|
33
|
+ }
|
|
34
|
+
|
24
|
35
|
return result;
|
25
|
36
|
}
|
26
|
37
|
|
|
@@ -28,6 +39,7 @@ public class PersonHandler {
|
28
|
39
|
|
29
|
40
|
public String forLoop() {
|
30
|
41
|
String result = "";
|
|
42
|
+
|
31
|
43
|
// identify initial value
|
32
|
44
|
// identify terminal condition
|
33
|
45
|
// identify increment
|
|
@@ -39,6 +51,16 @@ public class PersonHandler {
|
39
|
51
|
// append `stringRepresentation` to `result` variable
|
40
|
52
|
// end loop
|
41
|
53
|
|
|
54
|
+ int initial;
|
|
55
|
+ int termCon = personArray.length;
|
|
56
|
+ int increment = 1;
|
|
57
|
+
|
|
58
|
+ for (initial = 0; initial < termCon; initial += increment) {
|
|
59
|
+ Person currentPerson = personArray[initial];
|
|
60
|
+ String stringRepresentation = currentPerson.toString();
|
|
61
|
+ result = result.concat(stringRepresentation);
|
|
62
|
+ }
|
|
63
|
+
|
42
|
64
|
return result;
|
43
|
65
|
}
|
44
|
66
|
|
|
@@ -46,6 +68,7 @@ public class PersonHandler {
|
46
|
68
|
|
47
|
69
|
public String forEachLoop() {
|
48
|
70
|
String result = "";
|
|
71
|
+
|
49
|
72
|
// identify array's type
|
50
|
73
|
// identify array's variable-name
|
51
|
74
|
|
|
@@ -55,6 +78,11 @@ public class PersonHandler {
|
55
|
78
|
// append `stringRepresentation` to `result` variable
|
56
|
79
|
// end loop
|
57
|
80
|
|
|
81
|
+ for (Person currentPerson : personArray) {
|
|
82
|
+ String stringRepresentation = currentPerson.toString();
|
|
83
|
+ result = result.concat(stringRepresentation);
|
|
84
|
+ }
|
|
85
|
+
|
58
|
86
|
return result;
|
59
|
87
|
}
|
60
|
88
|
|