++,--运算符的使用

来源:互联网 发布:mac添加农历 编辑:程序博客网 时间:2024/06/05 23:46
/*++,--运算符的使用:单独使用:放在操作数的前面和后面效果一样。(这种用法是我们比较常见的)参与运算使用:放在操作数的前面,先自增或者自减,然后再参与运算。放在操作数的后面,先参与运算,再自增或者自减。作用:就是对变量进行自增1或者自减1。*/class OperatorDemo2 {public static void main(String[] args) {//意外的类型,常量是不可以这样做的//System.out.println(10++);//参与运算使用int a = 3;int b = 4;//int c = a++;//int d = b--;int c = ++a;int d = --b;System.out.println("a:"+a); //4, 4System.out.println("b:"+b); //3, 3System.out.println("c:"+c); //3, 4System.out.println("d:"+d); //4, 3}}

0 0