public class HelloWorld{
public static void main(String[] args) {
int one = 10 ;
int two = 20 ;
int three = 0 ;
three=one+two;
three+=one;
three-=one;
three*=one;
three/=one;
three%=one;
System.out.println("three=one+two==>"+three);
System.out.println("three+=one==>"+three);
System.out.println("three-=one==>"+three);
System.out.println("three*=one==>"+three);
System.out.println("three/=one==>"+three);
System.out.println("three%=one==>"+three);
}
}
前面每附一个值就保存一个值,如果不输出来,后来赋值运算符会将原来的值改变。最终你的输出只会是最后一个运算值
因为变量的值在程序运行过程中是可以改变的。如果不在每一步运算的时候将three的结果输出,而是连续运算最后输出,那么最后的结果就都是最后一次运算的结果。因为每一次运算结果都将之前的变量值覆盖了。希望可以帮到你
int one = 10 ;
int two = 20 ;
int three = 0 ;
three=one+two;//30 = 10 + 20;
three+=one;// 30 += 10; 等于three= 30 +10;现在three的值为40
three-=one;// 40 -= 10; 等于three= 30 - 10;现在three的值为30
three*=one;// 30 *= 10; 等于three= 30 * 10;现在three的值为300
three/=one;// 300 /= 10; 等于three= 300 /10;现在three的值为30
three%=one;//30 %= 10;等于three= 30 %10;现在three的值为0
/*
System.out.println("three=one+two==>"+three);
System.out.println("three+=one==>"+three);
System.out.println("three-=one==>"+three);
System.out.println("three*=one==>"+three);
System.out.println("three/=one==>"+three);
System.out.println("three%=one==>"+three);
*/
以上输出最终只会输出最后一个three, 0;