Skip to content

Commit 0639135

Browse files
committed
read through ch09
1 parent c54190d commit 0639135

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

ch09/Max.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import java.util.Arrays;
2+
3+
/**
4+
* Demonstrates command-line arguments.
5+
*/
6+
public class Max {
7+
8+
public static void main(String[] args) {
9+
System.out.println(Arrays.toString(args));
10+
11+
int max = Integer.MIN_VALUE;
12+
for (String arg : args) {
13+
int value = Integer.parseInt(arg);
14+
if (value > max) {
15+
max = value;
16+
}
17+
}
18+
}
19+
}

ch09/StringsThings.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,6 @@ public static void main(String[] args) {
2828
}
2929
System.out.println();
3030

31-
String fruit = "banana";
32-
33-
for (int i = 0; i < fruit.length(); i++) {
34-
char letter = fruit.charAt(i);
35-
System.out.println(letter);
36-
}
37-
3831
String name1 = "Alan Turing";
3932
String name2 = "Ada Lovelace";
4033
if (name1.equals(name2)) {
@@ -50,6 +43,17 @@ public static void main(String[] args) {
5043
System.out.println("name2 comes before name1.");
5144
}
5245

53-
System.out.println(reverse(name1));
46+
String fruit = "banana";
47+
48+
for (int i = 0; i < fruit.length(); i++) {
49+
char letter = fruit.charAt(i);
50+
System.out.println(letter);
51+
}
52+
53+
for (char letter : fruit.toCharArray()) {
54+
System.out.println(letter);
55+
}
56+
57+
System.out.println(reverse(fruit));
5458
}
5559
}

0 commit comments

Comments
 (0)