|
@@ -1,3 +1,5 @@
|
|
1
|
+package FirstSaturday;
|
|
2
|
+
|
1
|
3
|
import com.sun.org.apache.xpath.internal.SourceTree;
|
2
|
4
|
|
3
|
5
|
import java.awt.SystemTray;
|
|
@@ -17,10 +19,13 @@ public class WriteLoops {
|
17
|
19
|
|
18
|
20
|
public int oneToFive() {
|
19
|
21
|
int w = 0;
|
20
|
|
-
|
|
22
|
+ for(int i=1;i<=5;i++)
|
|
23
|
+ {
|
|
24
|
+ w = w + 1;
|
|
25
|
+ }
|
21
|
26
|
// Write a FOR loop that counts from 1 to 10.
|
22
|
27
|
// calling
|
23
|
|
- w = w + 1;
|
|
28
|
+
|
24
|
29
|
// each time through the loop
|
25
|
30
|
|
26
|
31
|
// this will tell the test how many times the loop executed.
|
|
@@ -29,10 +34,13 @@ public class WriteLoops {
|
29
|
34
|
|
30
|
35
|
public int oneToTen() {
|
31
|
36
|
int w = 0;
|
32
|
|
-
|
|
37
|
+ for(int i=1;i<=10;i++)
|
|
38
|
+ {
|
|
39
|
+ w = w + 1;
|
|
40
|
+ }
|
33
|
41
|
// Write a FOR loop that counts from 1 to 10.
|
34
|
42
|
// calling
|
35
|
|
- w = w + 1;
|
|
43
|
+
|
36
|
44
|
// each time through the loop
|
37
|
45
|
|
38
|
46
|
return w;
|
|
@@ -40,10 +48,13 @@ public class WriteLoops {
|
40
|
48
|
|
41
|
49
|
public int startAtTwentyOne() {
|
42
|
50
|
int w = 0;
|
43
|
|
-
|
|
51
|
+ for(int i=21;i<=31;i++)
|
|
52
|
+ {
|
|
53
|
+ w = w + 1;
|
|
54
|
+ }
|
44
|
55
|
// Write a FOR loop that makes 10 iterations, start at 21.
|
45
|
56
|
// calling
|
46
|
|
- w = w + 1;
|
|
57
|
+
|
47
|
58
|
// each time through the loop
|
48
|
59
|
|
49
|
60
|
return w;
|
|
@@ -51,10 +62,13 @@ public class WriteLoops {
|
51
|
62
|
|
52
|
63
|
public int countDown() {
|
53
|
64
|
int w = 0;
|
54
|
|
-
|
|
65
|
+ for(int i=100;i<=0;i--)
|
|
66
|
+ {
|
|
67
|
+ w = w + 1;
|
|
68
|
+ }
|
55
|
69
|
// Write a FOR loop that counts down from 100 to 0.
|
56
|
70
|
// calling
|
57
|
|
- w = w + 1;
|
|
71
|
+
|
58
|
72
|
// each time through the loop
|
59
|
73
|
|
60
|
74
|
return w;
|
|
@@ -62,20 +76,26 @@ public class WriteLoops {
|
62
|
76
|
|
63
|
77
|
public int byTwoTo32() {
|
64
|
78
|
int w = 0;
|
65
|
|
-
|
|
79
|
+ for(int i=0;i<=32;i=i+2)
|
|
80
|
+ {
|
|
81
|
+ w = w + 1;
|
|
82
|
+ }
|
66
|
83
|
// Write a FOR loop from 0 to 32 by 2s.
|
67
|
84
|
// calling
|
68
|
|
- w = w + 1;
|
|
85
|
+
|
69
|
86
|
// each time through the loop
|
70
|
87
|
return w;
|
71
|
88
|
}
|
72
|
89
|
|
73
|
90
|
public int countDownFrom5000() {
|
74
|
91
|
int w = 0;
|
75
|
|
-
|
|
92
|
+ for(int i=1;i<5001;i=i+11)
|
|
93
|
+ {
|
|
94
|
+ w = w + 1;
|
|
95
|
+ }
|
76
|
96
|
// Write a FOR loop from 1 to less than 5001 by 11s.
|
77
|
97
|
// calling
|
78
|
|
- w = w + 1;
|
|
98
|
+
|
79
|
99
|
// each time through the loop
|
80
|
100
|
|
81
|
101
|
return w;
|
|
@@ -83,11 +103,18 @@ public class WriteLoops {
|
83
|
103
|
|
84
|
104
|
public int nestedFors() {
|
85
|
105
|
int w = 0;
|
86
|
|
-
|
|
106
|
+ for(int i=0;i<20;i++)
|
|
107
|
+ {
|
|
108
|
+ for(int j=0; j<=4;j++)
|
|
109
|
+ {
|
|
110
|
+ w = w + 1;
|
|
111
|
+ }
|
|
112
|
+
|
|
113
|
+ }
|
87
|
114
|
// Write a nested FOR loop(s), where one counts from
|
88
|
115
|
// 0 to less than 20 and the inner one counts from 0 to 4
|
89
|
116
|
// calling
|
90
|
|
- w = w + 1;
|
|
117
|
+
|
91
|
118
|
// each time through the inner loop
|
92
|
119
|
|
93
|
120
|
return w;
|
|
@@ -95,14 +122,21 @@ public class WriteLoops {
|
95
|
122
|
|
96
|
123
|
public int helloZipCode() {
|
97
|
124
|
int w = 0;
|
98
|
|
-
|
|
125
|
+ for(int i=5;i<=105;i++)
|
|
126
|
+ {
|
|
127
|
+ if(i>51)
|
|
128
|
+ {
|
|
129
|
+ System.out.println("Hello Zipcode");
|
|
130
|
+ }
|
|
131
|
+
|
|
132
|
+ }
|
99
|
133
|
// Write a FOR loop that counts from 5 to 105. Put an IF
|
100
|
134
|
// statement inside the loop that checks the
|
101
|
135
|
// loop index counter and if it’s greater than 51,
|
102
|
136
|
// prints “Hello Zipcode” instead of the statement w = w + 1;
|
103
|
137
|
|
104
|
138
|
// calling
|
105
|
|
- w = w + 1;
|
|
139
|
+
|
106
|
140
|
// each time through the inner loop
|
107
|
141
|
|
108
|
142
|
return w;
|
|
@@ -131,7 +165,7 @@ public class WriteLoops {
|
131
|
165
|
// After the loop is done, print “Honey, I’m Home!”
|
132
|
166
|
public int driveHome() {
|
133
|
167
|
int w = 0;
|
134
|
|
-
|
|
168
|
+
|
135
|
169
|
// you need to use a .equals for two Strings.
|
136
|
170
|
|
137
|
171
|
// calling
|