|
@@ -20,7 +20,9 @@ public class WriteLoops {
|
20
|
20
|
|
21
|
21
|
// Write a FOR loop that counts from 1 to 10.
|
22
|
22
|
// calling
|
|
23
|
+ for(int i=1;i<6;i++){
|
23
|
24
|
w = w + 1;
|
|
25
|
+ }
|
24
|
26
|
// each time through the loop
|
25
|
27
|
|
26
|
28
|
// this will tell the test how many times the loop executed.
|
|
@@ -32,7 +34,9 @@ public class WriteLoops {
|
32
|
34
|
|
33
|
35
|
// Write a FOR loop that counts from 1 to 10.
|
34
|
36
|
// calling
|
|
37
|
+ for(int i=1;i<11;i++){
|
35
|
38
|
w = w + 1;
|
|
39
|
+ }
|
36
|
40
|
// each time through the loop
|
37
|
41
|
|
38
|
42
|
return w;
|
|
@@ -43,7 +47,9 @@ public class WriteLoops {
|
43
|
47
|
|
44
|
48
|
// Write a FOR loop that makes 10 iterations, start at 21.
|
45
|
49
|
// calling
|
|
50
|
+ for(int i=21;i<32;i++){
|
46
|
51
|
w = w + 1;
|
|
52
|
+ }
|
47
|
53
|
// each time through the loop
|
48
|
54
|
|
49
|
55
|
return w;
|
|
@@ -54,7 +60,9 @@ public class WriteLoops {
|
54
|
60
|
|
55
|
61
|
// Write a FOR loop that counts down from 100 to 0.
|
56
|
62
|
// calling
|
|
63
|
+ for(int i=100;i>0;i--){
|
57
|
64
|
w = w + 1;
|
|
65
|
+ }
|
58
|
66
|
// each time through the loop
|
59
|
67
|
|
60
|
68
|
return w;
|
|
@@ -65,7 +73,10 @@ public class WriteLoops {
|
65
|
73
|
|
66
|
74
|
// Write a FOR loop from 0 to 32 by 2s.
|
67
|
75
|
// calling
|
68
|
|
- w = w + 1;
|
|
76
|
+ for(int i=0;i<=32;i+=2){
|
|
77
|
+ w=w+1;
|
|
78
|
+ }
|
|
79
|
+
|
69
|
80
|
// each time through the loop
|
70
|
81
|
return w;
|
71
|
82
|
}
|
|
@@ -75,7 +86,9 @@ public class WriteLoops {
|
75
|
86
|
|
76
|
87
|
// Write a FOR loop from 1 to less than 5001 by 11s.
|
77
|
88
|
// calling
|
|
89
|
+ for(int i=1;i<5001;i+=11){
|
78
|
90
|
w = w + 1;
|
|
91
|
+ }
|
79
|
92
|
// each time through the loop
|
80
|
93
|
|
81
|
94
|
return w;
|
|
@@ -87,7 +100,12 @@ public class WriteLoops {
|
87
|
100
|
// Write a nested FOR loop(s), where one counts from
|
88
|
101
|
// 0 to less than 20 and the inner one counts from 0 to 4
|
89
|
102
|
// calling
|
|
103
|
+ for(int y=0;y<20;y++){
|
|
104
|
+ for(int x=0;x<5;x++){
|
90
|
105
|
w = w + 1;
|
|
106
|
+ }
|
|
107
|
+ }
|
|
108
|
+
|
91
|
109
|
// each time through the inner loop
|
92
|
110
|
|
93
|
111
|
return w;
|
|
@@ -102,7 +120,13 @@ public class WriteLoops {
|
102
|
120
|
// prints “Hello Zipcode” instead of the statement w = w + 1;
|
103
|
121
|
|
104
|
122
|
// calling
|
105
|
|
- w = w + 1;
|
|
123
|
+ for(int i=5;i<106;i++){
|
|
124
|
+ if (i<52){
|
|
125
|
+ w = w + 1;
|
|
126
|
+ } else {
|
|
127
|
+ System.out.println("Hello Zipcode");
|
|
128
|
+ }
|
|
129
|
+ }
|
106
|
130
|
// each time through the inner loop
|
107
|
131
|
|
108
|
132
|
return w;
|
|
@@ -135,12 +159,18 @@ public class WriteLoops {
|
135
|
159
|
// you need to use a .equals for two Strings.
|
136
|
160
|
|
137
|
161
|
// calling
|
138
|
|
- w = w + 1;
|
|
162
|
+ while (!gpsCurrentLocation().equals("Home")){
|
|
163
|
+ driveSomeMore();
|
|
164
|
+ w = w + 1;
|
|
165
|
+ }
|
|
166
|
+ System.out.println("Honey, I'm Home!");
|
|
167
|
+ return w;
|
|
168
|
+ }
|
139
|
169
|
// each time through the inner loop
|
140
|
170
|
|
141
|
171
|
|
142
|
|
- return w;
|
143
|
|
- }
|
|
172
|
+
|
|
173
|
+
|
144
|
174
|
|
145
|
175
|
// Getting harder...
|
146
|
176
|
// First declare and set “highestScore” to 236. Then set “currentScore” to
|
|
@@ -157,7 +187,12 @@ public class WriteLoops {
|
157
|
187
|
// do your while loop here
|
158
|
188
|
|
159
|
189
|
// calling
|
160
|
|
- w = w + 1;
|
|
190
|
+ while (runningScore<highestScore){
|
|
191
|
+ runningScore+=currentScore;
|
|
192
|
+ currentScore=gameNextScore();
|
|
193
|
+ w = w + 1;
|
|
194
|
+ }
|
|
195
|
+
|
161
|
196
|
// each time through the inner loop
|
162
|
197
|
|
163
|
198
|
return w; // >= 3;
|
|
@@ -172,12 +207,15 @@ public class WriteLoops {
|
172
|
207
|
int runningScore = 0;
|
173
|
208
|
|
174
|
209
|
// do your while loop here
|
|
210
|
+ do { currentScore=gameNextScore();
|
|
211
|
+ runningScore+=currentScore;
|
|
212
|
+ w = w + 1;
|
|
213
|
+ } while (runningScore<=highestScore);
|
175
|
214
|
|
176
|
215
|
// calling
|
177
|
|
- w = w + 1;
|
|
216
|
+
|
178
|
217
|
// each time through the inner loop
|
179
|
|
-
|
180
|
|
- return w >= 3;
|
|
218
|
+return w >= 3;
|
181
|
219
|
}
|
182
|
220
|
|
183
|
221
|
// Write a WHILE loop that checks “serverIsRunning()” and if true
|
|
@@ -188,9 +226,18 @@ public class WriteLoops {
|
188
|
226
|
int w = 0;
|
189
|
227
|
String adminPhoneNumber = "+1 202 456 1111";
|
190
|
228
|
|
|
229
|
+ while(serverIsRunning()) {
|
|
230
|
+ waitFor(5);
|
|
231
|
+ w = w + 1;
|
|
232
|
+ }
|
|
233
|
+ if (!serverIsRunning()){
|
|
234
|
+ sendEmergencyText("Help!",adminPhoneNumber);
|
|
235
|
+ tryServerRestart("Help!",adminPhoneNumber);
|
|
236
|
+ }
|
|
237
|
+
|
191
|
238
|
|
192
|
239
|
// calling
|
193
|
|
- w = w + 1;
|
|
240
|
+
|
194
|
241
|
// each time through the inner loop
|
195
|
242
|
|
196
|
243
|
return w;
|
|
@@ -201,8 +248,11 @@ public class WriteLoops {
|
201
|
248
|
// and if it is, add 7 to “i”
|
202
|
249
|
public int loop50by7() {
|
203
|
250
|
int w = 0;
|
|
251
|
+ int i=7;
|
204
|
252
|
|
205
|
|
-
|
|
253
|
+while(i<50){
|
|
254
|
+ i+=7;
|
|
255
|
+}
|
206
|
256
|
// calling
|
207
|
257
|
w = w + 1;
|
208
|
258
|
// each time through the inner loop
|