Kr Younger 6 gadus atpakaļ
vecāks
revīzija
67b7ec8da1
1 mainītis faili ar 25 papildinājumiem un 69 dzēšanām
  1. 25
    69
      WriteLoops.java

+ 25
- 69
WriteLoops.java Parādīt failu

@@ -18,11 +18,9 @@ public class WriteLoops {
18 18
         int w = 0;
19 19
 
20 20
         // Write a FOR loop that counts from 1 to 10.
21
-        for (int i = 1; i <= 5; i++) {
22 21
             // calling
23 22
             w = w + 1;
24 23
             // each time through the loop
25
-        }
26 24
 
27 25
         // this will tell the test how many times the loop executed.
28 26
         return w;
@@ -32,11 +30,10 @@ public class WriteLoops {
32 30
         int w = 0;
33 31
 
34 32
         // Write a FOR loop that counts from 1 to 10.
35
-        for (int i = 1; i <= 10; i++) {
36 33
         // calling
37 34
         w = w + 1;
38 35
         // each time through the loop
39
-        }
36
+        
40 37
         return w;
41 38
     }
42 39
 
@@ -44,11 +41,10 @@ public class WriteLoops {
44 41
         int w = 0;
45 42
 
46 43
         // Write a FOR loop that makes 10 iterations, start at 21.
47
-        for (int i = 21; i <= (21 + 10); i++) {
48 44
         // calling
49 45
         w = w + 1;
50 46
         // each time through the loop
51
-        }
47
+        
52 48
         return w;
53 49
     }
54 50
 
@@ -56,11 +52,10 @@ public class WriteLoops {
56 52
         int w = 0;
57 53
 
58 54
         // Write a FOR loop that counts down from 100 to 0.
59
-        for (int i = 100; i > 0; i--) {
60 55
         // calling
61 56
         w = w + 1;
62 57
         // each time through the loop
63
-        }
58
+        
64 59
         return w;
65 60
     }
66 61
 
@@ -68,11 +63,9 @@ public class WriteLoops {
68 63
         int w = 0;
69 64
 
70 65
         // Write a FOR loop from 0 to 32 by 2s.
71
-        for (int i = 0; i == 32; i += 2) {
72 66
         // calling
73 67
         w = w + 1;
74 68
         // each time through the loop
75
-        }
76 69
         return w;
77 70
     }
78 71
 
@@ -80,11 +73,10 @@ public class WriteLoops {
80 73
         int w = 0;
81 74
 
82 75
         // Write a FOR loop from 1 to less than 5001 by 11s.
83
-        for (int i = 1; i < 5001; i = i + 11) {
84 76
         // calling
85 77
         w = w + 1;
86 78
         // each time through the loop
87
-        }
79
+        
88 80
         return w;
89 81
     }
90 82
 
@@ -93,13 +85,10 @@ public class WriteLoops {
93 85
 
94 86
         // Write a nested FOR loop(s), where one counts from
95 87
         // 0 to less than 20 and the inner one counts from 0 to 4
96
-        for (int i = 0; i < 20; i++) {
97
-            for (int j = 0; j <= 4; j++) {
98 88
                 // calling
99 89
                 w = w + 1;
100 90
                 // each time through the inner loop
101
-            }
102
-        }
91
+
103 92
         return w;
104 93
     }
105 94
 
@@ -110,14 +99,11 @@ public class WriteLoops {
110 99
         // statement inside the loop that checks the
111 100
         // loop index counter and if it’s greater than 51,
112 101
         // prints “Hello Zipcode” instead of the statement w = w + 1;
113
-        for (int index = 5; index < 105; index++) {
114
-            if (index > 51) {
115
-                System.out.print("Hello Zipcode ");
116
-            } else
102
+
117 103
                 // calling
118 104
                 w = w + 1;
119 105
             // each time through the inner loop
120
-        }
106
+        
121 107
         return w;
122 108
     }
123 109
 
@@ -146,14 +132,13 @@ public class WriteLoops {
146 132
         int w = 0;
147 133
 
148 134
         // you need to use a .equals for two Strings.
149
-        while (gpsCurrentLocation().equalsIgnoreCase("Home") == false) {
150
-            driveSomeMore();
135
+
151 136
             // calling
152 137
             w = w + 1;
153 138
             // each time through the inner loop
154
-        }
155
-        System.out.println("Honey, I’m Home!");
156
-        return w;
139
+        
140
+
141
+            return w;
157 142
     }
158 143
 
159 144
     // Getting harder...
@@ -169,15 +154,11 @@ public class WriteLoops {
169 154
         int runningScore = 0;
170 155
 
171 156
         // do your while loop here
172
-        while (runningScore < highestScore) {
173
-            // do your ifs here
174
-            runningScore += currentScore;
175
-            currentScore = gameNextScore();
157
+ 
176 158
             // calling
177 159
             w = w + 1;
178 160
             // each time through the inner loop
179
-        }
180
-        System.out.println(w);
161
+        
181 162
         return w; // >= 3;
182 163
     }
183 164
 
@@ -190,13 +171,10 @@ public class WriteLoops {
190 171
         int runningScore = 0;
191 172
 
192 173
         // do your while loop here
193
-        do {
194
-            runningScore += currentScore;
195
-            currentScore = gameNextScore();
174
+
196 175
             // calling
197 176
             w = w + 1;
198 177
             // each time through the inner loop
199
-        } while (currentScore < highestScore);
200 178
 
201 179
         return w >= 3;
202 180
     }
@@ -209,15 +187,10 @@ public class WriteLoops {
209 187
         int w = 0;
210 188
         String adminPhoneNumber = "+1 202 456 1111";
211 189
         
212
-        while (serverIsRunning()) {
213
-            waitFor(5);
190
+
214 191
         // calling
215 192
         w = w + 1;
216 193
         // each time through the inner loop
217
-        }
218
-        if (serverIsRunning() == false) {
219
-            sendEmergencyText("Help!", adminPhoneNumber);
220
-        }
221 194
         
222 195
         return w;
223 196
     }
@@ -228,14 +201,11 @@ public class WriteLoops {
228 201
     public int loop50by7() {
229 202
         int w = 0;
230 203
 
231
-        int i = 7;
232 204
 
233
-        while (i < 50) {
234
-            i = i + 7;
235 205
             // calling
236 206
             w = w + 1;
237 207
             // each time through the inner loop
238
-        }
208
+        
239 209
         return w;
240 210
     }
241 211
 
@@ -268,13 +238,11 @@ public class WriteLoops {
268 238
         int w = 0;
269 239
         int sumOfThrees = 0;
270 240
 
271
-        for (int index = 0; index < threes_array.length; index++) {
272
-            sumOfThrees = sumOfThrees + threes_array[index];
273
-
241
+ 
274 242
             // calling
275 243
             w = w + 1;
276 244
             // each time through the inner loop
277
-        }
245
+        
278 246
         System.out.print("The Sum is ");
279 247
         System.out.println(sumOfThrees);
280 248
 
@@ -287,14 +255,11 @@ public class WriteLoops {
287 255
         int w = 0;
288 256
         int sumOfThrees = 0;
289 257
 
290
-        int index = 0;
291
-        while (index < threes_array.length) {
292
-            sumOfThrees = sumOfThrees + threes_array[index];
293
-            index++;
258
+ 
294 259
             // calling
295 260
             w = w + 1;
296 261
             // each time through the inner loop
297
-        }
262
+        
298 263
         System.out.print("The Sum is ");
299 264
         System.out.println(sumOfThrees);
300 265
 
@@ -313,16 +278,11 @@ public class WriteLoops {
313 278
         boolean onTime = true;
314 279
 
315 280
         // ADD YOUR CODE here.
316
-        boolean yardNeedsMowed = true;
317
-        while (isSummer()) {
318
-            if (yardNeedsMowed) {
319
-                yellAtJuniorToMowLawn();
320
-            }
281
+ 
321 282
             // be sure to call
322 283
             w = w + 1;
323 284
             // each time inside the loop
324
-        }
325
-        sendJuniorBackToSchool("first Day Of school");
285
+        
326 286
         return w;
327 287
     }
328 288
 
@@ -335,12 +295,11 @@ public class WriteLoops {
335 295
         int w = 0;
336 296
         int numberOfVotes = voteTallies.length;
337 297
 
338
-        for (int index = 0; index < numberOfVotes; index++) {
339
-            System.out.println(voteTallies[index]);
298
+ 
340 299
             // calling
341 300
             w = w + 1;
342 301
             // each time through the inner loop
343
-        }
302
+        
344 303
         return w;
345 304
     }
346 305
 
@@ -351,14 +310,11 @@ public class WriteLoops {
351 310
         int w = 0;
352 311
         int numberOfVotes = voteTallies.length;
353 312
 
354
-        int index = 0;
355 313
 
356
-        while (index < numberOfVotes) {
357
-            System.out.println(voteTallies[index]);
358 314
             // calling
359 315
             w = w + 1;
360 316
             // each time through the inner loop
361
-        }
317
+        
362 318
         return w;
363 319
     }
364 320