x =(x = 1)+(x = 2)*(++ x)*(x ++) - 为什么这个表达式19的输出?

mah*_*hdi -6 java core operators

我执行了代码,输出是19,但我不明白为什么.

public static void main(String[] args) 
{
    int x = 0;
    x = (x = 1) + (x = 2) * (++x) * (x++);
    System.out.println(x);
}
Run Code Online (Sandbox Code Playgroud)

Era*_*ran 8

您从左到右评估操作数,然后在加法运算符之前计算乘法运算符:

x = (x = 1) + (x = 2) * (++x)  *      (x++);

       1    +    (2    *   3   *       3     )  = 19

    assignment          pre            post
    operator            increment      increment
    returns the         returns the    returns the
    assigned value      incremented    value before
                        value          it was incremented
Run Code Online (Sandbox Code Playgroud)