Skip to content

Commit 03ddfe4

Browse files
committed
reviewed appendixes
1 parent bcd64d6 commit 03ddfe4

8 files changed

Lines changed: 73 additions & 57 deletions

File tree

appb/DigitUtil.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Utility class for extracting digits from integers.
3+
*
4+
* @author Chris Mayfield
5+
* @version 1.0
6+
*/
7+
public class DigitUtil {
8+
9+
/**
10+
* Tests whether x is a single digit integer.
11+
*
12+
* @param x the integer to test
13+
* @return true if x has one digit, false otherwise
14+
*/
15+
public static boolean isSingleDigit(int x) {
16+
if (x > -10 && x < 10) {
17+
return true;
18+
} else {
19+
return false;
20+
}
21+
}
22+
23+
public static boolean isSingleDigit2(int x) {
24+
return x > -10 && x < 10;
25+
}
26+
27+
public static void main(String[] args) {
28+
System.out.println(isSingleDigit(2));
29+
boolean bigFlag = !isSingleDigit(17);
30+
31+
int z = 9;
32+
if (isSingleDigit(z)) {
33+
System.out.println("z is small");
34+
} else {
35+
System.out.println("z is big");
36+
}
37+
}
38+
39+
}

appb/Goodbye.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Example program that demonstrates print vs println.
3+
*/
4+
public class Goodbye {
5+
6+
/**
7+
* Prints a greeting.
8+
*/
9+
public static void main(String[] args) {
10+
System.out.print("Goodbye, "); // note the space
11+
System.out.println("cruel world");
12+
}
13+
}

appe/Digit.java

Lines changed: 0 additions & 18 deletions
This file was deleted.

appe/Tables.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,3 @@ public static void main(String[] args) {
4343
}
4444

4545
}
46-
47-
48-
public static void printTable4(int rows) {
49-
for (int i = 1; i <= rows; i = i + 1) {
50-
printRow3(i, rows);
51-
}
52-
}
53-
54-
public static void printRow4(int n, int cols) {
55-
int i;
56-
for (i = 1; i <= cols; i = i + 1) {
57-
System.out.printf("%4d", n * i);
58-
}
59-
System.out.println(i);
60-
}
61-

appe/Unreachable.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
public class Unreachable {
2+
3+
public static double absoluteValue(double x) {
4+
if (x < 0) {
5+
return -x;
6+
} else {
7+
return x;
8+
}
9+
}
10+
11+
public static void main(String[] args) {
12+
System.out.println("absolute value");
13+
System.out.println(absoluteValue(-2));
14+
}
15+
16+
}

appe/Vowels.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
/**
2+
* Example switch statement with cases that fall through.
3+
*/
14
public class Vowels {
25

36
public static void main(String[] args) {
47
String s = "Ahoy!";
58
for (int i = 0; i < s.length(); i++) {
6-
9+
710
// display the next character
811
char c = s.charAt(i);
912
System.out.print(c + " is a ");
@@ -39,4 +42,5 @@ public static void main(String[] args) {
3942
}
4043
}
4144
}
45+
4246
}

ch05/Circle.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
*/
44
public class Circle {
55

6-
public static double absoluteValue(double x) {
7-
if (x < 0) {
8-
return -x;
9-
} else {
10-
return x;
11-
}
12-
}
13-
146
public static double calculateArea(double radius) {
157
double result = Math.PI * radius * radius;
168
return result;
@@ -61,9 +53,6 @@ public static double calculateArea2(double radius) {
6153

6254
public static void main(String[] args) {
6355

64-
System.out.println("absolute value");
65-
System.out.println(absoluteValue(-2));
66-
6756
System.out.println("calculateArea");
6857
System.out.println(calculateArea(3.0));
6958

ch08/Series.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
*/
44
public class Series {
55

6-
public static boolean isSingleDigit(int x) {
7-
return x > -10 && x < 10;
8-
}
9-
106
public static int factorial(int n) {
117
if (n == 0) {
128
return 1;
@@ -25,13 +21,6 @@ public static int fibonacci(int n) {
2521

2622
public static void main(String[] args) {
2723

28-
int z = 9;
29-
if (isSingleDigit(z)) {
30-
System.out.println("z is small");
31-
} else {
32-
System.out.println("z is big");
33-
}
34-
3524
System.out.println("factorial");
3625
System.out.println(factorial(3));
3726

0 commit comments

Comments
 (0)