对码输出的结果有些不解

来源:3-3 Java中的赋值运算符

时代风云

2016-10-11 15:55

        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呢?还有为什么每个输出的结果都是大于输出的值呢?

写回答 关注

1回答

  • 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

    时代风云

    非常谢谢你的解释。

    2016-10-12 13:51:00

    共 1 条回复 >

Java入门第一季(IDEA工具)升级版

0基础萌新入门第一课,从Java环境搭建、工具使用、基础语法开始

1165171 学习 · 17581 问题

查看课程

相似问题