X Tutup
Skip to content

Commit a4a66aa

Browse files
committed
changed all let with int
1 parent 19b329e commit a4a66aa

27 files changed

+336
-318
lines changed

appendixa.adoc

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ Now, if you wanted to print out each item's name in the grocery list to the cons
7979

8080
[source]
8181
----
82-
let idx = 0;
82+
int idx = 0;
8383
while (idx < groceries.length) {
84-
console.log(groceries[idx].name);
84+
System.out.println(groceries[idx].name);
8585
idx = idx + 1;
8686
}
8787
----
@@ -95,7 +95,7 @@ Rather, how about this:
9595
[source]
9696
----
9797
groceries.forEach((item) => {
98-
console.log(item.name);
98+
System.out.println(item.name);
9999
});
100100
----
101101

@@ -113,7 +113,7 @@ Say we wanted to get a list of just the prices of our grocery list. If we use a
113113

114114
[source]
115115
----
116-
let index = 0;
116+
int index = 0;
117117
const prices = [];
118118
while (index < groceries.length) {
119119
prices.push(groceries[index].price);
@@ -125,7 +125,7 @@ But if we use a different higher-order function, `map`:
125125

126126
[source]
127127
----
128-
let prices = groceries.map((item) => {
128+
int prices = groceries.map((item) => {
129129
return item.price;
130130
});
131131
----
@@ -134,8 +134,8 @@ The value of prices would be: `[5.5,14.99,6.49,4.79,3.99]`. And if we were to wa
134134

135135
[source]
136136
----
137-
let index = 0;
138-
let total = 0;
137+
int index = 0;
138+
int total = 0;
139139
while (index < groceries.length) {
140140
total = total + groceries[index].price;
141141
index = index + 1;
@@ -149,7 +149,7 @@ But look how much simpler our code can be if we use `reduce`, another higher-ord
149149

150150
[source]
151151
----
152-
let total = groceries.reduce((sum, item) => {
152+
int total = groceries.reduce((sum, item) => {
153153
return sum += item.price;
154154
}, 0);
155155
----
@@ -164,7 +164,7 @@ function even (value) {
164164
return value % 2 === 0;
165165
}
166166
167-
console.log(even(3), even(4), even(126));
167+
System.out.println(even(3), even(4), even(126));
168168
169169
// giving us 'false true true'
170170
----
@@ -197,9 +197,9 @@ function even (value) {
197197
return value % 2 === 0;
198198
}
199199
200-
let dataList = [1,2,3,4];
200+
int dataList = [1,2,3,4];
201201
202-
console.log(
202+
System.out.println(
203203
filter(dataList, even)
204204
); // produces [2,4]
205205
@@ -219,12 +219,12 @@ And I can reduce it even more to something like this:
219219

220220
[source]
221221
----
222-
let result = [1,2,3,4].filter(
222+
int result = [1,2,3,4].filter(
223223
function (value) {return value % 2 === 0}
224224
);
225225
226226
// or, If I have 'dataList' defined as [1,2,3,4]
227-
let result = dataList.filter(
227+
int result = dataList.filter(
228228
function (value) {return value % 2 === 0}
229229
);
230230
----
@@ -260,7 +260,7 @@ const discount = (amount, code) => {
260260
}
261261
}; // whew! that a lot of braces.
262262
263-
let netprice = discount(200.00, 'HALFOFF'); // would be 100.
263+
int netprice = discount(200.00, 'HALFOFF'); // would be 100.
264264
----
265265

266266
But think about adding another discount, we'd have to add another `if`, more braces, and make sure we nest it in there carefully, otherwise we break the whole, rickety, mess.
@@ -282,7 +282,7 @@ const discount = (amount, code) => {
282282
}
283283
};
284284
285-
let netprice = discount(200.00, 'HALFOFF'); // would be 100.
285+
int netprice = discount(200.00, 'HALFOFF'); // would be 100.
286286
----
287287

288288
We have to add two lines of code for each `case`.

appendixb.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function printString(string) {
115115
// print long strings with new lines the them.
116116
let a = string.split(/\r?\n/);
117117
for (i = 0; i < a.length; i++) {
118-
console.log(a[i]);
118+
System.out.println(a[i]);
119119
}
120120
}
121121

arithmeticexpr.adoc

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ is to
2121
// And in Java:
2222
// a = b3 - 6
2323
24-
let b = 3;
25-
let a = b * 3 - 6;
26-
console.log(a); // -> 3
24+
int b = 3;
25+
int a = b * 3 - 6;
26+
System.out.println(a); // -> 3
2727
----
2828

2929
Now you try it.
@@ -41,10 +41,10 @@ Take a moment and write down your solution before reading on.
4141

4242
[source]
4343
----
44-
let q = 0;
45-
let j = 5;
44+
int q = 0;
45+
int j = 5;
4646
q = 2 * j + 20;
47-
console.log(q); // -> 30
47+
System.out.println(q); // -> 30
4848
----
4949

5050
Let's try another...
@@ -64,9 +64,9 @@ and print out x.
6464
My solution is pretty simple.
6565
[source]
6666
----
67-
let y = 2;
68-
let x = 5 * y + Math.pow(y, 3) - 7;
69-
console.log(x); // -> 11
67+
int y = 2;
68+
int x = 5 * y + Math.pow(y, 3) - 7;
69+
System.out.println(x); // -> 11
7070
----
7171

7272
=== _Trigonometry_
@@ -89,10 +89,10 @@ Formula: A = h * b / 2
8989

9090
[source]
9191
----
92-
let height = 20;
93-
let base = 10;
94-
let areaOfaTriangle = height * base / 2;
95-
console.log(areaOfaTriangle); // -> 100
92+
int height = 20;
93+
int base = 10;
94+
int areaOfaTriangle = height * base / 2;
95+
System.out.println(areaOfaTriangle); // -> 100
9696
----
9797

9898

@@ -106,9 +106,9 @@ Hint: You'll need to use a constant Math property!
106106

107107
[source]
108108
----
109-
let radius = 7.7;
110-
let area = Math.PI * Math.pow(radius, 2);
111-
console.log(area); // -> 186.26502843133886 (wow)
109+
int radius = 7.7;
110+
int area = Math.PI * Math.pow(radius, 2);
111+
System.out.println(area); // -> 186.26502843133886 (wow)
112112
----
113113

114114

arrays.adoc

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Now, if you're the coder of this game you could keep track of each player's heal
77

88
[source]
99
----
10-
let playerZeroHealthScore = 100;
11-
let playerOneHealthScore = 100;
12-
let playerTwoHealthScore = 100;
13-
let playerThreeHealthScore = 100;
14-
let playerFourHealthScore = 100;
10+
int playerZeroHealthScore = 100;
11+
int playerOneHealthScore = 100;
12+
int playerTwoHealthScore = 100;
13+
int playerThreeHealthScore = 100;
14+
int playerFourHealthScore = 100;
1515
----
1616

1717
If we setup these 5 variables, our game can track 5 players! But *we'd have to change the game's code to track SIX players.* Well, that not good. Kind of silly actually.
@@ -20,15 +20,15 @@ To get around this kind of problem we use an *array*. We could ask, "how many pl
2020

2121
[source]
2222
----
23-
let playerHealthScores = [100, 100, 100, 100, 100];
23+
int playerHealthScores = [100, 100, 100, 100, 100];
2424
----
2525

2626
Now, like a _string_, array indexes start at zero.
2727

2828
[source]
2929
----
3030
// 0 1 2 3 4
31-
let playerHealthScores = [100, 100, 100, 100, 100];
31+
int playerHealthScores = [100, 100, 100, 100, 100];
3232
----
3333

3434
This array is a *data structure* - a way for us to keep track of lots of data in a controlled fashion. (We can make arrays any size.)
@@ -63,11 +63,11 @@ Declaring and initializing some arrays in Java:
6363

6464
[source]
6565
----
66-
let donuts = ["chocolate", "glazed", "jelly"];
66+
int donuts = ["chocolate", "glazed", "jelly"];
6767
68-
let arrayofLetters = ['c','h','r','i','s'];
68+
int arrayofLetters = ['c','h','r','i','s'];
6969
70-
let mixedData = ['one', 2, true]; // a string, a number and a boolean!
70+
int mixedData = ['one', 2, true]; // a string, a number and a boolean!
7171
----
7272

7373
=== Accessing elements of an Array
@@ -77,23 +77,23 @@ strings to identify our donuts. Sometimes, we say something like "donuts sub 2"
7777

7878
[source]
7979
----
80-
let donuts = ["chocolate", "glazed", "jelly"];
80+
int donuts = ["chocolate", "glazed", "jelly"];
8181
82-
console.log(donuts[0]); // "chocolate" (we could say "donuts sub zero")
82+
System.out.println(donuts[0]); // "chocolate" (we could say "donuts sub zero")
8383
84-
console.log(donuts[2]); // "jelly"
84+
System.out.println(donuts[2]); // "jelly"
8585
----
8686
=== Adding to an Array
8787

8888
We can also add things to the end of the array.
8989

9090
[source]
9191
----
92-
let donuts = ["chocolate", "glazed", "jelly"];
92+
int donuts = ["chocolate", "glazed", "jelly"];
9393
9494
donuts[3] = "strawberry" // notice there is no element 3 before this,
9595
96-
console.log(donuts); // but after, there are now 4 things in the array.
96+
System.out.println(donuts); // but after, there are now 4 things in the array.
9797
----
9898

9999
=== Get the size of an Array
@@ -102,9 +102,9 @@ We can use the *length* property to find the size of an array.
102102

103103
[source]
104104
----
105-
let donuts = ["chocolate", "glazed", "jelly"];
105+
int donuts = ["chocolate", "glazed", "jelly"];
106106
107-
console.log(donuts.length); // it'll print 3
107+
System.out.println(donuts.length); // it'll print 3
108108
----
109109

110110
Note: A string is an ARRAY of single characters
@@ -116,15 +116,15 @@ If we use the _length_ property carefully, we can always get the last element in
116116

117117
[source]
118118
----
119-
let donuts = ["chocolate", "glazed", "jelly"];
119+
int donuts = ["chocolate", "glazed", "jelly"];
120120
121121
donuts[3] = "strawberry"; // -> ["chocolate", "glazed", "jelly", "strawberry"]
122122
123-
console.log(donuts[donuts.length - 1]); // strawberry
123+
System.out.println(donuts[donuts.length - 1]); // strawberry
124124
125125
donuts[4] = "powdered" // -> ["chocolate", "glazed", "jelly", "strawberry", "powdered"]
126126
127-
console.log(donuts[donuts.length - 1]); // powdered
127+
System.out.println(donuts[donuts.length - 1]); // powdered
128128
----
129129

130130
=== Append to the Array
@@ -133,13 +133,13 @@ We can also use the `.length` to add to the end of the array!
133133

134134
[source]
135135
----
136-
let donuts = ["chocolate", "glazed", "jelly"];
136+
int donuts = ["chocolate", "glazed", "jelly"];
137137
138138
donuts[donuts.length] = "strawberry";
139-
console.log(donuts[donuts.length - 1]); // strawberry
139+
System.out.println(donuts[donuts.length - 1]); // strawberry
140140
141141
donuts[donuts.length] = "powdered";
142142
143-
console.log(donuts[donuts.length - 1]); // powdered
143+
System.out.println(donuts[donuts.length - 1]); // powdered
144144
----
145145

booleanexpr.adoc

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ We also need more kinds of boolean expressions when we are programming. Things l
3535

3636
[source, Java]
3737
----
38-
let healthScore = 5;
38+
int healthScore = 5;
3939
----
4040

4141
We need a way to ask about expressions like "is healthScore less than 7?? (very healthy)" or
@@ -130,20 +130,20 @@ why coders need to be able to use them to get the software *just right*.
130130
====
131131
* Create 2 variables to use for a comparison
132132
* Use at least two comparison operators in Java
133-
* And print them "console.log(2 > 1)"
133+
* And print them "System.out.println(2 > 1)"
134134
====
135135

136136
Here is an example:
137137

138138
[source]
139139
----
140-
let houseTemp = 67.0;
141-
let thermostatSetting = 70.0;
140+
int houseTemp = 67.0;
141+
int thermostatSetting = 70.0;
142142
143-
console.log(houseTemp >= 55.0);
144-
console.log(houseTemp <= thermostatSetting);
145-
console.log(thermostatSetting != 72.0);
146-
console.log(houseTemp > 65.0 && thermostatSetting == 68.0)
143+
System.out.println(houseTemp >= 55.0);
144+
System.out.println(houseTemp <= thermostatSetting);
145+
System.out.println(thermostatSetting != 72.0);
146+
System.out.println(houseTemp > 65.0 && thermostatSetting == 68.0)
147147
----
148148

149149
These log statements should produce TRUE, TRUE, TRUE and FALSE.

break.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ while (true) {
1313
1414
execute(cmd);
1515
}
16-
console.log("Exiting.")
16+
System.out.println("Exiting.")
1717
----
1818

1919
Here, you are asking the user to type in a command. If the command is "exit", then quit the loop and output "Exiting", and end the program.
@@ -33,13 +33,13 @@ for (let i = 0; i < 10; i++) {
3333
// will only be true if the number is even
3434
if (i % 2 === 0) continue;
3535
36-
console.log(i); // prints 1, then 3, 5, 7, 9
36+
System.out.println(i); // prints 1, then 3, 5, 7, 9
3737
}
3838
----
3939

4040
What's interesting here is the use of the remainder operator (%) to see if a number is odd.
4141
The expression (i % 2) is zero if the number is even, if not, the number must be odd.
4242
You want to remember this trick of how to find odd or even numbers.
4343
It's a common programming problem that you will get asked.
44-
The continue statement starts the loop over, not letting the console.log to print out the number when it's even.
44+
The continue statement starts the loop over, not letting the System.out.println to print out the number when it's even.
4545

consolelog.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class Main {
6868
}
6969
----
7070

71-
That comment at the end of the console.log line is showing what you can expect to see in the output. Here it would be "3.5" printed by itself. Try it in your bookmarked Repl.
71+
That comment at the end of the System.out.println line is showing what you can expect to see in the output. Here it would be "3.5" printed by itself. Try it in your bookmarked Repl.
7272

7373
We can also add useful stuff to the .log call.
7474

0 commit comments

Comments
 (0)
X Tutup