怎么样让three+=one;打印的值以three=0为基础,而不是30.

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

劉3535446

2022-08-16 02:05

 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;打印的值以three=0为基础从而输出10,而不是40.

写回答 关注

2回答

  • weixin_慕娘4490471
    2022-08-28 01:33:08

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

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

                        three = three-=one;

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

                            three = three*=one; 

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

                                three = three/=one;

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

                                    three = three%=one;

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

        }

    }


  • weixin_慕村3084428
    2022-08-19 21:54:03

     int one = 10 ;

            int two = 20 ;

            int three = 0;

            three=one+two;(改一下int a=one+two;)

             System.out.println("three = one + two ==>  "+three);(相应的这边对应为a)

            three+=one;(此时设int b=a+one=one+two+one=40,three+=one=0

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


    劉35354... 回复劉35354...

    打错了,在three+=one上面一行加

    2022-08-20 15:02:38

    共 2 条回复 >

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

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

1165538 学习 · 17586 问题

查看课程

相似问题