About i ++ and ++ i

 

Look at the code, guess what output value

@Test 
public void Test () {
int I =. 1;
int A, B = 0;
I ++;
A = (I ++);
System.out.println (A);
System.out.println (I);
the System.out. the println (B ++);
System.out.println (B ++);

for (int = 0 K; K <. 5; K ++) {
System.out.println (K);
}
for (int = S 0; S <. 5 ; S ++) {
System.out.println (S);
}
}

The following comments about I added, the final paste at the output
@Test 
public void the Test () {
int i = 1; // define a variable i, ++ operation is only possible after initialization, otherwise it will compile error
int a, b = 0; // definition of a and b, a not initialize
i ++; // i automatic execution + 1'd
a = (I +); // assigned to I a, the place with the place there is a difference, a is the assignment is obtained before ++, and not because of the increase in brackets +1 on the first execution after the assignment
System.out.println (A);
System.out.println (I);
System.out.println (B ++);
System.out.println (B ++);

for (int K 0 =; K <. 5; K ++) {
System.out.println (K);
}
for (int = S 0; S <. 5; S ++) {
System.out.println (S);
}
}

As a result, you counting on you

1
2
0
2
0
1
2
3
4
0
1
2
3
4

Process finished with exit code 0

Guess you like

Origin www.cnblogs.com/shej123/p/12028733.html
I
"I"
I: