
#i means assigning the value first and then calculating, i means calculating first and then assigning the value.
The example is as follows:
package com.test;
/**
* @author Administrator
* @date 2018/6/9
*/
public class TestAdd {
public static void main(String[] args) {
int a = 0;
int b = a++;
int c = ++a;
System.out.println("a:" + a);
System.out.println("b:" + b);
System.out.println("c:" + c);
}
}int b = a ; means first assign the value of a to b, and then calculate 1.
int c = a; means first calculating the value of a, 1, and then assigning the value of a to c.
If there is no variable to receive a or the value of a, simply using these two operations will make no difference in the result.
The same is true for a-- and--a.
Recommended tutorial: java quick start
The above is the detailed content of The difference between i++ and ++i in java. For more information, please follow other related articles on the PHP Chinese website!