Understanding the output of an arithmatic expression

后端 未结 2 1525
-上瘾入骨i
-上瘾入骨i 2021-01-27 09:24

I have a java class as follows:

class A{
    public static void main(String[] args){
       int a=10;
       a*=a++ +a;
       System.out.println(a);
    }
}

Ou         


        
2条回答
  •  梦毁少年i
    2021-01-27 09:47

    Consider 15.7.1. Evaluate Left-Hand Operand section of java specs where it says - First, the left-hand operand is evaluated to produce a variable then the value of the right-hand operand are used to perform the binary operation indicated by the compound assignment operator

    In your case it is a = 10 * ((11)+10) = 201

提交回复
热议问题