forked from hellokaton/write-readable-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample3.java
More file actions
34 lines (28 loc) · 701 Bytes
/
Copy pathExample3.java
File metadata and controls
34 lines (28 loc) · 701 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
package chapter_08;
/**
* 三目运算符
*
* @author biezhi
* @date 2018/7/11
*/
public class Example3 {
int hour;
public void part1() {
String timeString = (hour >= 12) ? "pm" : "am";
if(hour >= 12){
timeString = "pm";
} else {
timeString = "am";
}
}
public int part2() {
int exponent = 20; // 计算出来的值
int mantissa = -1; // 为了演示写死了
if(exponent >= 0){
return mantissa * (1 << exponent);
}
return mantissa / (1 << exponent);
// return exponent >= 0 ? mantissa * (1 << exponent) :
// mantissa / (1 << exponent);
}
}