java关于i++和++i一段很有意思的代码

读完本篇文章可以基本了解Java中的i++以及++i…

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
int a = 0;
a = ++a + a++;
System.out.println("a=" + a);

int b = 0;
b = b++ + ++b;// b=0+(1+1)
System.out.println("b=" + b);

int c = 0;
c = c++ + c;// c=0+1
System.out.println("c=" + c);

int d = 0;
d = ++d + d;// d=1+1
System.out.println("d=" + d);

int e = 0;
e = ++e + ++e;// e=1+2
System.out.println("e=" + e);

int f = 0;
f = f++ + f++;// f= 0+1
System.out.println("f=" + f);

int g = 0;
int h;
g = g++;// g=0
System.out.println("g=" + g);
g = g++;// g=0
System.out.println("g=" + g);
h = g++;// h=0 g=1
System.out.println("g=" + g + ",h=" + h);

int i = 0;
i = i++ + 2; // i=0+2
System.out.println(i);

int j = 0;
j = ++j + 2;// j=1+2
System.out.println(j);

int x = 9;
int y = 10;
int z;
z = (++x == y) ? ++x : y--;//++x;++x;z=11;
System.out.println("x=" + x + ",y=" + y + ",z=" + z);

int m = 0;
boolean b1 = m++ == 1;// false
boolean b2 = m++ == 1 || m == 1;// true