File tree Expand file tree Collapse file tree 11 files changed +157
-8
lines changed Expand file tree Collapse file tree 11 files changed +157
-8
lines changed Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ enable = true # whether or not to enable section folding
15
15
level = 0 # the depth to start folding
16
16
17
17
[preprocessor .features ]
18
- command = " python3 features.java "
18
+ command = " python3 features.py "
19
19
# Going to start writing the rest of the book
20
20
# Assuming this is true
21
21
toplevel_anonymous_class = false
File renamed without changes.
Original file line number Diff line number Diff line change @@ -294,6 +294,12 @@ Javadoc and Documentation comments
294
294
- [Inner Classes]()
295
295
- [Annotations]()
296
296
- [Reflection]()
297
+
298
+ The terminal
299
+ javac
300
+ java
301
+ javadoc
302
+ jshell
297
303
-->
298
304
299
305
<!--
Original file line number Diff line number Diff line change 1
1
# Challenges
2
+
3
+ Remember the rules for this are
4
+
5
+ * Try to use only the information given up to this point in this book.
6
+ * Try not to give up until you've given it a solid attempt
7
+
8
+ ## Challenge 1.
9
+
10
+ Write a method named ` printSquare ` which takes one ` int ` argument named ` size ` .
11
+
12
+ The ` size ` argument should control how big of a square is output.
13
+
14
+ ``` java
15
+ // CODE HERE
16
+
17
+ void main() {
18
+ printSquare(4 );
19
+ System . out. println();
20
+
21
+ printSquare(3 );
22
+ System . out. println();
23
+
24
+ printSquare(2 );
25
+ System . out. println();
26
+
27
+ printSquare(1 );
28
+ System . out. println();
29
+ }
30
+ ```
31
+
32
+ ## Challenge 2.
33
+
34
+ What happens if a negative number is given to your ` printSquare ` ?
35
+
36
+ Make it so that if a negative number is given, it works the same as if a positive number
37
+ was given.
38
+
39
+
40
+ ``` java
41
+ // CODE HERE
42
+
43
+ void main() {
44
+ printSquare(3 );
45
+ System . out. println();
46
+ printSquare(- 3 );
47
+ System . out. println();
48
+
49
+ System . out. println();
50
+ printSquare(- 2 );
51
+ System . out. println();
52
+ printSquare(2 );
53
+ }
54
+ ```
55
+
56
+ ## Challenge 3.
Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ void main() {
31
31
32
32
This has the same use as regular final variables. If there are lots of lines
33
33
of code where a variable might be reassigned, it can be useful to not have
34
- to read all that code to know that it does happen.
34
+ to read all that code to know that it does happen.[ ^ opinion ]
35
35
36
- Generally though, adding final to arguments make it harder to read the code, simply
36
+ [ ^ opinion ] : Adding ` final ` to all arguments can make it harder to read the code, simply
37
37
because of visual noise.
Original file line number Diff line number Diff line change @@ -98,3 +98,51 @@ Do it using a `for` loop and again using a `while` loop.
98
98
99
99
## Challenge 5.
100
100
101
+ Draw a square.
102
+
103
+ Make it so that you can make the square bigger or smaller by
104
+ changing a variable at the start of the program.
105
+
106
+ ```
107
+ *****
108
+ *****
109
+ *****
110
+ *****
111
+ ```
112
+
113
+ ## Challenge 6.
114
+
115
+ Draw a rectangle.
116
+
117
+ Make it so that you can make the rectangle bigger or smaller in either dimension by
118
+ changing a variable at the start of the program.
119
+
120
+ ```
121
+ ******
122
+ ******
123
+ ******
124
+ ```
125
+
126
+ ## Challenge 7.
127
+
128
+ Draw a circle!
129
+
130
+ Make it so that you can make the circle bigger or smaller by
131
+ changing a variable at the start of the program.
132
+
133
+ ```
134
+ **
135
+ ****
136
+ ******
137
+ ********
138
+ ******
139
+ ****
140
+ **
141
+ ```
142
+
143
+ ## Challenge 8.
144
+
145
+ Draw a smiley face!
146
+
147
+ Make it so that you can make the smile bigger or smaller by
148
+ changing a variable at the start of the program.
Original file line number Diff line number Diff line change 1
1
# Labeled Continue
2
2
3
3
Labeled continues also work the same in ` for ` loops as ` while ` loops, but with the hopefully expected caveat that
4
- the statement of a ` for ` loop will always run when you get to the top of it.
4
+ the statement of a ` for ` loop will always run when you get to the top of it.[ ^ uncommon ]
5
5
6
6
``` java
7
7
label:
Original file line number Diff line number Diff line change @@ -5,4 +5,39 @@ Remember the rules for this are
5
5
* Try to use only the information given up to this point in this book.
6
6
* Try not to give up until you've given it a solid attempt
7
7
8
- ##
8
+ ## Challenge 1.
9
+
10
+ Declare a method named ` printSquare ` . When invoked it should print a square.
11
+
12
+ ``` java
13
+ // CODE HERE
14
+
15
+ void main() {
16
+ printSquare();
17
+ }
18
+ ```
19
+
20
+ ## Challenge 2.
21
+
22
+ Declare a method named ` printSquareThreeTimes ` . When invoked it should print three squares
23
+ by invoking a method named ` printSquare ` three times.
24
+
25
+ ``` java
26
+ // CODE HERE
27
+
28
+ // Code from challenge 1 here
29
+
30
+ void main() {
31
+ printSquareThreeTimes();
32
+ }
33
+ ```
34
+
35
+ ## Challenge 3.
36
+
37
+ Write a program that contains at least four methods. Have fun with it.
38
+
39
+ ``` java
40
+ void main() {
41
+ // sing a song or something.
42
+ }
43
+ ```
Original file line number Diff line number Diff line change 3
3
The ` main ` method works the same as any other method. Java just treats it special by choosing to
4
4
call it in order to start your programs.
5
5
6
+ ``` java
7
+ void main() {
8
+ System . out. println(" Java will start here" );
9
+ }
10
+ ```
11
+
6
12
This means you can do anything in your ` main ` method you can do in any other method, including returning early.
7
13
8
14
``` java
@@ -14,4 +20,5 @@ void main() {
14
20
}
15
21
16
22
System . out. println(" WONT RUN" );
17
- }
23
+ }
24
+ ```
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments