|
|
@@ -18,9 +18,11 @@ public class WriteLoops {
|
|
18
|
18
|
public int oneToFive() {
|
|
19
|
19
|
int w = 0;
|
|
20
|
20
|
|
|
21
|
|
- // Write a FOR loop that counts from 1 to 10.
|
|
|
21
|
+ // Write a FOR loop that counts from 1 to 5.
|
|
22
|
22
|
// calling
|
|
|
23
|
+ for (int i = 1; i <=5; 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
|
|
35
|
|
- w = w + 1;
|
|
|
37
|
+ for (int i = 1; i <=10; i++){
|
|
|
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
|
|
46
|
|
- w = w + 1;
|
|
|
50
|
+ for (int i = 21; i <=31; i++){
|
|
|
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
|
|
57
|
|
- w = w + 1;
|
|
|
63
|
+ for (int i = 100; i > 0; i--){
|
|
|
64
|
+ w = w + 1;
|
|
|
65
|
+ }
|
|
58
|
66
|
// each time through the loop
|
|
59
|
67
|
|
|
60
|
68
|
return w;
|
|
|
@@ -65,7 +73,9 @@ 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 = 32; i <=0; i+=2){
|
|
|
77
|
+ w = w + 1;
|
|
|
78
|
+ }
|
|
69
|
79
|
// each time through the loop
|
|
70
|
80
|
return w;
|
|
71
|
81
|
}
|
|
|
@@ -75,7 +85,9 @@ public class WriteLoops {
|
|
75
|
85
|
|
|
76
|
86
|
// Write a FOR loop from 1 to less than 5001 by 11s.
|
|
77
|
87
|
// calling
|
|
78
|
|
- w = w + 1;
|
|
|
88
|
+ for (int i = 5001; i > 0; i-=11){
|
|
|
89
|
+ w = w + 1;
|
|
|
90
|
+ }
|
|
79
|
91
|
// each time through the loop
|
|
80
|
92
|
|
|
81
|
93
|
return w;
|