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

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

 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.

提问者:劉3535446 2022-08-16 02:05

个回答

  • 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);