three1是30.three1*=one應(yīng)該是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應(yīng)該是30*10=300啊。
2019-02-24
因為 three1最后一次賦值是在 three2=three1+=one?
等于 three2=three1=three1+one
由于之前已經(jīng)賦值three1=one+two=10+20=30
所以 three2=three1=three1+one=30+10=40
2019-02-24
"int three2 = three1 += one;"此時“three1”已被賦值為40;
"int three4 = three1 *= one; "此時計算為“40*10”。
如果你把“int three3 = three2 -= one; "中"three2"改為"three1"結(jié)果就是300。
2019-02-24
我剛把three1改成three2就顯示300了,three2不是40嗎,沒搞懂