forked from hellokaton/write-readable-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample5.java
More file actions
64 lines (57 loc) · 1.53 KB
/
Copy pathExample5.java
File metadata and controls
64 lines (57 loc) · 1.53 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package chapter_08;
/**
* 在方法/函数中提前返回
* 最小化嵌套
*
* @author biezhi
* @date 2018/7/11
*/
public class Example5 {
public boolean contains(String str, String subString) {
if (str == null || subString == null) {
return false;
}
if (subString.equals("")) {
return true;
}
return str.indexOf(subString) != -1;
}
final int SUCCESS = 200;
// public void part1() {
// int userResult = 200;
// int permissionResult = 300;
//
// String message = "";
// if (userResult == SUCCESS) {
// if (permissionResult != SUCCESS) {
// message = "没有权限阅读";
// return;
// }
// message = "";
// } else {
// message = String.valueOf(userResult);
// }
// // 模拟使用 message
// System.out.println(message);
// }
public void part2() {
int userResult = 200;
int permissionResult = 300;
String message = "";
if(userResult != SUCCESS){
message = String.valueOf(userResult);
// 模拟使用 message
System.out.println(message);
return;
}
if (permissionResult != SUCCESS) {
message = "没有权限阅读";
// 模拟使用 message
System.out.println(message);
return;
}
message = "";
// 模拟使用 message
System.out.println(message);
}
}