Pre- and postincrement in Java

后端 未结 6 1761
不思量自难忘°
不思量自难忘° 2021-01-17 13:48

I just wanted to create a little Java-Puzzle, but I puzzled myself. One part of the puzzle is:

What does the following piece of code do:



        
6条回答
  •  醉酒成梦
    2021-01-17 14:22

    The output is 9 (try it)

    int i = 1;
    i += ++i + i++ + ++i;
    

    becomes

    i = 1 + 2 + 2 + 4
    

提交回复
热议问题