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

对码输出的结果有些不解

        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 += one ==>"+three);

        three -= one;

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

        three *= one;

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

        three /= one;

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

        three %= one;

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

输出的结果为:

three = one + two ==>30
three += one ==>40
three -= one ==>30
three *= one ==>300
three /= one ==>30
three %= one ==>0

倒数第二个结果不应该是3吗?three/=one不就是三十除十的结果吗?怎么是30呢?还有为什么每个输出的结果都是大于输出的值呢?

提问者:时代风云 2016-10-11 15:55

个回答

  • lm57208134141012
    2016-10-11 16:02:06
    已采纳

    three = one + two; //此时three=10+20=30

    three += one;//此时three=30+10=40

    three -= one;//此时three=40-10=30

    three *= one;//此时three=30*10=300

    three /= one;//此时three=300/10=30

    three %= one;此时three=30/10的余数0