集册 Java实例教程 递增(++)和递减(--)

递增(++)和递减(--)

—— 递增(++)和递减(

欢马劈雪     最近更新时间:2020-01-02 10:19:05

597
增量运算符有两种:

public class Main {/*来自 时代Java公众号*/

  public static void main(String[] args) {

    int i = 10; 

    i = i++ + i;   // Assigns 21 to i 

    i = 10; 

    i = ++i + i++; // Assigns 22 to i 

      

     

     i = 15; 

    int j = 16; 

    i--; 

    --i; 

    i = 10; 

    i = i--;       // Assigns 10 to i 

    i = 10; 

    j = i-- + 10;  // Assigns 20 to j and 9 to i 

    i = 10; 
    /**
    时代Java - N o w  J a v a . c o m
    **/

    j = --i + 10;  // Assigns 19 to j and 9 to i 

  }

}