Simran Bhutani преди 6 години
родител
ревизия
9c5498d7d9
променени са 1 файла, в които са добавени 11 реда и са изтрити 1 реда
  1. 11
    1
      src/main/java/com/zipcodewilmington/PersonHandler.java

+ 11
- 1
src/main/java/com/zipcodewilmington/PersonHandler.java Целия файл

12
 
12
 
13
     public String whileLoop() {
13
     public String whileLoop() {
14
         String result = "";
14
         String result = "";
15
+        int counter =0;
16
+        while(counter<personArray.length){
17
+            result= result.concat(personArray[counter].toString());
18
+            counter++;
19
+
20
+        }
15
         // assume there is a `counter`
21
         // assume there is a `counter`
16
         // while `counter` is less than length of array
22
         // while `counter` is less than length of array
17
             // begin loop
23
             // begin loop
28
 
34
 
29
     public String forLoop() {
35
     public String forLoop() {
30
         String result = "";
36
         String result = "";
31
-        // identify initial value
37
+        for(int counter=0; counter< personArray.length; counter++)
38
+            result=result.concat(personArray[counter].toString());// identify initial value
32
         // identify terminal condition
39
         // identify terminal condition
33
         // identify increment
40
         // identify increment
34
 
41
 
46
 
53
 
47
     public String forEachLoop() {
54
     public String forEachLoop() {
48
         String result = "";
55
         String result = "";
56
+        for(Person counter : personArray)
57
+            result= result.concat(counter.toString());
58
+
49
         // identify array's type
59
         // identify array's type
50
         // identify array's variable-name
60
         // identify array's variable-name
51
 
61