1 package Yuju;
2
3 public class yuju {
4
5 public static void main(String[] args) {
6 //
7
8 int age =18;
9
10 //分支语句
11 if(!(2<1||4>3))
12 {
13 System.out.println("我被执行了");
14 }
15 else
16 {
17 System.out.println("另外被执行了");
18 }
19
20 if(age<10)
21 {
22 System.out.println("小朋友,你好");
23 }
24 else if(age>10&&age<18)
25 {
26 System.out.println("同学,你好");
27 }
28 else
29 {
30 System.out.println("朋友,你好");
31 }
32
33 //三元运算符?:
34 int a=0;
35
36 if(age>15)
37 {
38 a=15;
39 }
40 else
41 {
42 a=0;
43 }
44
45 System.out.println("a="+a);
46
47 int b=age>15?age:0;
48
49 age=23;
50
51 b=++age>23?(age++<25?--age:age++):--age;
52
53 System.out.println("b="+b);
54 System.out.println("age="+age);
55
56
57 int c=50;
58
59 switch(c)
60 {
61 case 20:
62
63 System.out.println("c="+c);
64 break;
65
66 case 30:
67
68 System.out.println("c="+c);
69 break;
70
71 case 40:
72
73 System.out.println("c="+c);
74 break;
75
76 default://其他情况
77 System.out.println("其他c="+c);
78
79 }
80
81 }
82
83 }