forked from ChrisMayfield/ThinkJavaCode2
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDigitUtil.java
More file actions
39 lines (34 loc) · 871 Bytes
/
DigitUtil.java
File metadata and controls
39 lines (34 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Utility class for extracting digits from integers.
*
* @author Chris Mayfield
* @version 1.0
*/
public class DigitUtil {
/**
* Tests whether x is a single digit integer.
*
* @param x the integer to test
* @return true if x has one digit, false otherwise
*/
public static boolean isSingleDigit(int x) {
if (x > -10 && x < 10) {
return true;
} else {
return false;
}
}
public static boolean isSingleDigit2(int x) {
return x > -10 && x < 10;
}
public static void main(String[] args) {
System.out.println(isSingleDigit(2));
boolean bigFlag = !isSingleDigit(17);
int z = 9;
if (isSingleDigit(z)) {
System.out.println("z is small");
} else {
System.out.println("z is big");
}
}
}