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

赋值运算符

这怎么写啊,有大佬给我示范一下么

提问者:橙汁梨儿 2021-04-12 20:49

个回答

  • weixin_慕桂英0467466
    2021-05-15 23:40:20

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

  • weixin_慕的地8373765
    2021-04-23 15:39:51

            int one = 10 ;

            int two = 20 ;

            int three = 0 ;

            int a=one+two;

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

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

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

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

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

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


  • 慕仔10573827
    2021-04-13 14:38:01

    =,把等号右边的数据赋值给等号左边的变量或常量

    +=,a += b,等效于:a = (a的数据类型)(a + (b));

    -=,a -= b,等效于:a = (a的数据类型)(a - (b));

    =,a = b,等效于:a = (a的数据类型)(a * (b));

    /=,a /= b,等效于:a = (a的数据类型)(a / (b));

    %=,a %= b,等效于:a = (a的数据类型)(a % (b));