问答详情
源自:3-3 Java中的赋值运算符

为什么答案是30

   three-=one;

        System.out.println("three -= one ==> "+three);


three 不是30吗 

one是10.

three-=one;为什么不是30-10=20呢?


--------------------------------------------------------

  three/=one;

        System.out.println("three /= one ==> "+three);

为什么不是30/10=3而是等于30呢

提问者:慕粉32 2016-04-20 23:40

个回答

  • soicor
    2016-04-21 00:14:21
    已采纳

    System.out.println("three+=one==>"+(three+=one));//three=30+10=40

    System.out.println("three-=one==>"+(three-=one));//three=40-10=30

    System.out.println("three*=one==>"+(three*=one));//three=30*10=300

    System.out.println("three/=one==>"+(three/=one));//three=300/10=30

    System.out.println("three%=one==>"+(three%=one));//three=30%10=0

    程序从上到下执行,没执行一步,three就被重新赋值


  • Robin_Yeung
    2016-04-21 00:11:53

    因为之前执行了一步 three += one; 相当于 three = three + one; 即three现在的值变成了40.

    所以再执行three -= one; 此时three的值就是30