java 自增自减运算

来源:互联网 发布:网络攻防实验 编辑:程序博客网 时间:2024/04/27 20:18
public static void main(String args[]){       int a = 3;//定义一个变量;       int b = ++a;//自增运算       int c = 3;       int d = --c;//自减运算       System.out.println("a:"+a+",b:"+b);       System.out.println("c:"+c+",d:"+d);   }

**a:4,b:4
c:2,d:2**

 public static void main(String args[]){         int a = 3;//定义一个变量;         int b = a++;//自增运算         int c = 3;         int d = c--;//自减运算         System.out.println("a:"+a+",b:"+b);         System.out.println("c:"+c+",d:"+d);   }

**a:4,b:3
c:2,d:3**

从上边的运行结果可以看出来,先增还是后增,操作数的值都会增加,只是返回的值不一样。先增,后返回的是增加后的值,后增,返回的是之前的值

原创粉丝点击