++ --

java基础语法:++ --

public class AdditionAndSubtraction {
    //java基础语法 ++ --  /  前++ 后++  前-- 后--
    public static void main(String[] args) {
        int a = 10;
        int b = 20;
        int c = 30;
        //随便写一个例子:
        //要求写出:
        //a = ? --- 13
        //b = ? ---- 18
        //c = ? --- 31
        //result = ? -- 74
        int result = a++ + c-- + b-- + a++ + c++ - ++a - ++c + --b;
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
        System.out.println(result);


        /**
          这个是:计算着类的方法:
         eg: int a = 10
         eg:result = a++
         1- 在result先写=10  、  2- a再写=11
         因为:a++ 属于后++:所以在result里面还是10,回到a之后才是11
         a = 11
         result = 10
         
         -------------------------------------------------------------

         eg: int a = 10
         eg:result = ++a
         1- 在result先写=11  、  2- a再写=11
         因为:++a 属于前++:所以在result已经是a+1=11 ,回到a之后是11
         a = 11
         result = 11
         */
        // 1- 先把全部写出来
        //a = 11  12  13
        //b = 19  18
        //c = 29  30  31
        //result =  10 + 30  + 20 + 11 + 29  - 13 - 31 + 18

    }
}

posted on 2022-07-26 18:59  陈嘻嘻-  阅读(750)  评论(0编辑  收藏  举报

导航