Since the difference between the left and right by auto-incremented

 

Left increment (  ++ A ) and right increment ( A ++  ) difference

 

++ and - both the left operand can occur, it can also appear on the right, but the result is different

Left increment example:

public  class Demo {
     public  static  void main (String [] args) {
         int a =. 5 ;
         int B ++ = a; // make the implementation of a first increment, and then assigned to B 
        System.out.println ( "a" A +); // output 6 
        System.out.println ( "B" + B); // output 6 
    } 
}

Right increment example:

public  class Demo {
     public  static  void main (String [] args) {
         int a =. 5 ;
         int B = a ++; // to a first value assigned to the variable b, and then perform the self-energizing 
        System.out.println ( "a "+ A); // output. 6 
        System.out.println (" B "+ B); // output 5 
    } 
}

 

note:

Increment decrement operator operating variables can only be used, it can not be directly used to operate a constant value or!

 

class public Demo { 
public static void main (String [] args) {
int a = . 5 ;
int B ++ = a; // make a first implementation of the self-energizing , and then assigned to B
the System. OUT .println ( "a" A +); // output 6
. the System OUT .println ( "B" + B); // output 6
}
}

Guess you like

Origin www.cnblogs.com/libinhong/p/10988535.html