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

请问这里面是怎么计算

       int one = 10 ;
        int two = 20 ;
        int three = 0 ;

three+=one;

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

为什么得出的结果是40,不应该是10吗?

提问者:死神少 2015-12-23 06:18

个回答

  • 慕莱坞9220042
    2015-12-23 09:07:11
    已采纳

    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;望楼主采纳!

  • 慕前端5914160
    2015-12-23 07:07:09

    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


  • 慕前端5914160
    2015-12-23 07:03:55

    哪里啊?