three -=one为什么等于30?不是应该等于20么?

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

慕移动7058161

2021-08-07 07:36

three -=one为什么等于30?不是应该等于20么?

写回答 关注

3回答

  • 阿达西扬
    2022-02-25 00:40:52

    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);    //现在three=30

            System.out.println(three+=one);    //现在three=40

            System.out.println(three-=one);    //现在three=30 

            System.out.println(three*=one);    //现在three=300

            System.out.println(three/=one);    //现在three=30

            System.out.println(three%=one);    //现在three=0

    /*

    每一次输出都在对three重新赋值然后进行下面的继续运算

    不知道这样说合理不

    */

  • 慕仔7570475
    2021-08-25 14:52:29

     three+=one;

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

    //这时候等于40

             three-=one;

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

    //这时候用上个式子的结果再减one就是40-10也就等于30了

  • weixin_精慕门4326742
    2021-08-07 11:16:05

    //第一行是说three= one + two ==> +three 所以是等于30

    //第二行是说three += one ==> +three  所以是等于40

    //第三行是说three -= one ==> +three 所以是用40-10+0=30

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

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

1163393 学习 · 17551 问题

查看课程

相似问题