|
@@ -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
|
|
- w = w + 1;
|
|
23
|
+ for (int i =0;i<5;i++) {
|
|
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 =0; i<10;i++) {
|
35
|
38
|
w = w + 1;
|
|
39
|
+ }
|
36
|
40
|
// each time through the loop
|
37
|
41
|
|
38
|
42
|
return w;
|
|
@@ -43,7 +47,10 @@ 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>10; i--) {
|
46
|
51
|
w = w + 1;
|
|
52
|
+ }
|
|
53
|
+
|
47
|
54
|
// each time through the loop
|
48
|
55
|
|
49
|
56
|
return w;
|
|
@@ -54,18 +61,23 @@ public class WriteLoops {
|
54
|
61
|
|
55
|
62
|
// Write a FOR loop that counts down from 100 to 0.
|
56
|
63
|
// calling
|
|
64
|
+ for (int i =100; i>0;i--) {
|
57
|
65
|
w = w + 1;
|
|
66
|
+ }
|
58
|
67
|
// each time through the loop
|
59
|
68
|
|
60
|
69
|
return w;
|
61
|
70
|
}
|
62
|
71
|
|
|
72
|
+
|
63
|
73
|
public int byTwoTo32() {
|
64
|
74
|
int w = 0;
|
65
|
75
|
|
66
|
76
|
// Write a FOR loop from 0 to 32 by 2s.
|
67
|
77
|
// calling
|
|
78
|
+ /*for (int i =0; i<32; i += 2) {
|
68
|
79
|
w = w + 1;
|
|
80
|
+ } */
|
69
|
81
|
// each time through the loop
|
70
|
82
|
return w;
|
71
|
83
|
}
|
|
@@ -75,7 +87,9 @@ public class WriteLoops {
|
75
|
87
|
|
76
|
88
|
// Write a FOR loop from 1 to less than 5001 by 11s.
|
77
|
89
|
// calling
|
|
90
|
+ for (int i = 5000; i>0;i-=11){
|
78
|
91
|
w = w + 1;
|
|
92
|
+ }
|
79
|
93
|
// each time through the loop
|
80
|
94
|
|
81
|
95
|
return w;
|
|
@@ -87,7 +101,11 @@ public class WriteLoops {
|
87
|
101
|
// Write a nested FOR loop(s), where one counts from
|
88
|
102
|
// 0 to less than 20 and the inner one counts from 0 to 4
|
89
|
103
|
// calling
|
90
|
|
- w = w + 1;
|
|
104
|
+ for (int i = 0; i<20; i++){
|
|
105
|
+ for (int j = 0; j <= 4; j++){
|
|
106
|
+ w = w+1;
|
|
107
|
+ }
|
|
108
|
+ }
|
91
|
109
|
// each time through the inner loop
|
92
|
110
|
|
93
|
111
|
return w;
|
|
@@ -102,7 +120,11 @@ 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 <105; i++){
|
|
124
|
+ if (i <= 51) {
|
|
125
|
+ w =w + 1;
|
|
126
|
+ } else System.out.println("Hello Zipcode");
|
|
127
|
+ }
|
106
|
128
|
// each time through the inner loop
|
107
|
129
|
|
108
|
130
|
return w;
|
|
@@ -135,8 +157,12 @@ public class WriteLoops {
|
135
|
157
|
// you need to use a .equals for two Strings.
|
136
|
158
|
|
137
|
159
|
// calling
|
138
|
|
- w = w + 1;
|
|
160
|
+
|
139
|
161
|
// each time through the inner loop
|
|
162
|
+ while (gpsCurrentLocation() != ("Home")) {
|
|
163
|
+ driveSomeMore();
|
|
164
|
+ w = w+1;
|
|
165
|
+ }
|
140
|
166
|
|
141
|
167
|
|
142
|
168
|
return w;
|
|
@@ -157,7 +183,11 @@ public class WriteLoops {
|
157
|
183
|
// do your while loop here
|
158
|
184
|
|
159
|
185
|
// calling
|
160
|
|
- w = w + 1;
|
|
186
|
+ while (runningScore <= highestScore) {
|
|
187
|
+ runningScore = runningScore + currentScore;
|
|
188
|
+ w = w+1;
|
|
189
|
+ currentScore = gameNextScore();
|
|
190
|
+ }
|
161
|
191
|
// each time through the inner loop
|
162
|
192
|
|
163
|
193
|
return w; // >= 3;
|
|
@@ -172,7 +202,10 @@ public class WriteLoops {
|
172
|
202
|
int runningScore = 0;
|
173
|
203
|
|
174
|
204
|
// do your while loop here
|
175
|
|
-
|
|
205
|
+ do { runningScore = runningScore + currentScore;
|
|
206
|
+ w = w+1;
|
|
207
|
+ currentScore = gameNextScore();
|
|
208
|
+ } while (runningScore < highestScore);
|
176
|
209
|
// calling
|
177
|
210
|
w = w + 1;
|
178
|
211
|
// each time through the inner loop
|
|
@@ -187,10 +220,17 @@ public class WriteLoops {
|
187
|
220
|
public int checkServerStatus() {
|
188
|
221
|
int w = 0;
|
189
|
222
|
String adminPhoneNumber = "+1 202 456 1111";
|
|
223
|
+ while (serverIsRunning() == true) {
|
|
224
|
+ waitFor(5);
|
|
225
|
+ w= w+1;
|
|
226
|
+ }
|
|
227
|
+ if (serverIsRunning() == false) {
|
|
228
|
+ sendEmergencyText("Help!", adminPhoneNumber);
|
190
|
229
|
|
|
230
|
+ }
|
191
|
231
|
|
192
|
232
|
// calling
|
193
|
|
- w = w + 1;
|
|
233
|
+ //w = w + 1;
|
194
|
234
|
// each time through the inner loop
|
195
|
235
|
|
196
|
236
|
return w;
|