Is there a difference between x++ and ++x in java?

后端 未结 16 2750
-上瘾入骨i
-上瘾入骨i 2020-11-22 02:34

Is there a difference between ++x and x++ in java?

16条回答
  •  生来不讨喜
    2020-11-22 03:14

    ++x is called preincrement while x++ is called postincrement.

    int x = 5, y = 5;
    
    System.out.println(++x); // outputs 6
    System.out.println(x); // outputs 6
    
    System.out.println(y++); // outputs 5
    System.out.println(y); // outputs 6
    

提交回复
热议问题