请问这里面是怎么计算
int one = 10 ;
int two = 20 ;
int three = 0 ;
three+=one;
System.out.println("thrree+= ==> "+three);
为什么得出的结果是40,不应该是10吗?
2015-12-23
public class HelloWorld{ public static void main(String[] args) { int one = 10 ; int two = 20 ; int three = 0 ; three=one+two; System.out.println("three=one+two ==> "+three); three+=one; System.out.println("three+= ==> "+three); three-=one; System.out.println("three-+"+three); three*=one; System.out.println("three*="+three); three/=one; System.out.println("three/="+three); three%=one; System.out.println("three%="+three);
你好,three+=one; 这一句的意思是,three + one 赋值给 three,这里上面已经运行过 three=one+two;
所以到 three+=one; 这一步的时候 three 的值是 30;运行 three+=one; 后相当于 three = 30 + 10;
因此,得到的 three 的值是 40;望楼主采纳!
public class HelloWorld{ public static void main(String[] args) { int one = 10 ; int two = 20 ; int three = 0 ; three=one+two; System.out.println("three=one+two ==> "+three); //30 three+=one; System.out.println("thrree+= ==> "+three); //40 three-=one; System.out.println("three-+"+three); //30 three*=one; System.out.println("three*="+three); //300 three/=one; System.out.println("three/="+three); //30 three%=one; System.out.println("three%="+three); //0
举报