increment, decrement, operator

/*
Self-increment operator: ++
Self-decrement operator: --
Basic meaning: let the variable load or drop a number 1.
The way to use it: write it before the name of the variable or after the name of the variable. For example, ++i, i--
           1) used alone
           2) mixed use
Differences in use: 1) When used alone, there is no difference between before ++ and after ++
          2) When mixed use
          (1) If it is [ Before ++], [then the variable name will immediately +1] and then continue to use the result [add first and then use]
            (2) If it is [after ++], then first use the original value of the variable, [then let the variable + 1] [Use first and then add]
Precautions; only variables can be self-added or self-decremented
*/
public class fx{     public static void main(String[] args){         int a=10;         ++a;//Front+ +         System.out.println(a);         a++;//After ++         System.out.println(a);         int b=20;//Use with printing, the variable immediately becomes 21, and then prints the result 21         System. out.println(++b);//21








        int c=20;// First use the original value of the variable, and then let the variable +1
        System.out.println(c++);//20
        System.out.println(c);//21
        
        //It is related to the assignment operation Mixed
        int d=30;//Mixed use, the former--immediately-1 becomes 29, and then the obtained result 29 is passed to the variable e
        int e=--d;
        System.out.println(e);//39
        System.out.println(d);//39
        
        //Mixed use of
        int f=40;//After mixed use -- first hand over the original 40 to g, and then turn -1 into 39
        int g=f-- ;
        System.out.println(g);//40
        System.out.println(f);//39
        
        int num1=10;
        int num2=20;
        int num3=++num1+num2--;
        System.out. println(num1);//11
        System.out.println(num2);//19
        System.out.println(num3);//31
    }
}

 

Guess you like

Origin blog.csdn.net/weixin_45650003/article/details/119162048
Recommended