++,--。对当前变量值+1,-1。
Q:自增自减运算符在变量前后有区别吗?
1、如果单独使用没有区别。
2、非单独使用,在变量前,先进行变量自增自减,再使用变量。在变量后,先使用变量,再自增自减。
代码演示如下:
public class OperatorDemo1 {
public static void main(String[] args) {
// 自增自减,在表达式中或者不是单独操作的情况,++ --在变量前后存在区别
// ++ --在变量前面,先+ -再使用
int i = 10;
int j = ++i;
System.out.println("i = " + i);
System.out.println("j = " + j);
//++ --在变量后面,先使用再+ -
int m = 10;
int n = m--;
System.out.println("m = " + m);
System.out.println("n = " + n);
}
}