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啊。
因为 three1最后一次赋值是在 three2=three1+=one
等于 three2=three1=three1+one
由于之前已经赋值three1=one+two=10+20=30
所以 three2=three1=three1+one=30+10=40
"int three2 = three1 += one;"此时“three1”已被赋值为40;
"int three4 = three1 *= one; "此时计算为“40*10”。
如果你把“int three3 = three2 -= one; "中"three2"改为"three1"结果就是300。
我刚把three1改成three2就显示300了,three2不是40吗,没搞懂