Browse Source

stripped solns

Kr Younger 6 years ago
parent
commit
67b7ec8da1
1 changed files with 25 additions and 69 deletions
  1. 25
    69
      WriteLoops.java

+ 25
- 69
WriteLoops.java View File

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