-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSwitchAndIfTest.java
56 lines (54 loc) · 1.13 KB
/
SwitchAndIfTest.java
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
package java_core_basic;
/**
* if 和 switch 语句
* @author 唐龙
*/
public class SwitchAndIfTest {
public static void main(String[] args) {
// 如果使用if else
int day = 5;
if (day == 1) {
System.out.println("星期一");
} else if (day == 2) {
System.out.println("星期二");
} else if (day == 3) {
System.out.println("星期三");
} else if (day == 4) {
System.out.println("星期四");
} else if (day == 5) {
System.out.println("星期五");
} else if (day == 6) {
System.out.println("星期六");
} else if (day == 7) {
System.out.println("星期天");
} else {
System.out.println("这个是什么鬼?");
}
// 如果使用switch
switch (day) {
case 1:
System.out.println("星期一");
break;
case 2:
System.out.println("星期二");
break;
case 3:
System.out.println("星期三");
break;
case 4:
System.out.println("星期四");
break;
case 5:
System.out.println("星期五");
break;
case 6:
System.out.println("星期六");
break;
case 7:
System.out.println("星期天");
break;
default:
System.out.println("这个是什么鬼?");
}
}
}