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

three1是30.three1*=one应该是300啊。为什么是400?

public class HelloWorld{

    public static void main(String[] args) {

    int one = 10 ;

        int two = 20 ;

        int three = 0 ;

        int three1 = one + two;

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

        int three2 = three1 += one;

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

        int three3 = three2 -= one; 

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

        int three4 = three1 *= one; 

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

three4为什么显示的是400。three1 *=one应该是30*10=300啊。

提问者:慕先生7452772 2019-02-24 15:05

个回答

  • Dusdii
    2019-02-24 22:28:18

    因为 three1最后一次赋值是在 three2=three1+=one 

    等于 three2=three1=three1+one

    由于之前已经赋值three1=one+two=10+20=30

    所以 three2=three1=three1+one=30+10=40

  • 微笑的火龙果
    2019-02-24 19:28:19

    "int three2 = three1 += one;"此时“three1”已被赋值为40;

    "int three4 = three1 *= one; "此时计算为“40*10”。

    如果你把“int three3 = three2 -= one; "中"three2"改为"three1"结果就是300。

  • 慕先生7452772
    2019-02-24 15:08:47

    我刚把three1改成three2就显示300了,three2不是40吗,没搞懂