请教一下我这个编法的问题所在

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

慕函数9227957

2017-02-08 14:26

我是这样写的

int one = 10 ;

        int two = 20 ;

        int three = 0 ;

         three=one+two;

         three+=one;

         three-=one;

         three*=one;

         three/=one;

        three%=one;

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

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

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

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

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

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

我这样写的话里面的three就恒是0 是不是一定要按照给的答案那样编写three才不会一直为0啊

恳请解答一下!

写回答 关注

1回答

  • 慕粉1904487852
    2017-02-08 14:38:27
    已采纳

    程序执行时从上到下的,假如你执行一句,就输出结果,那么就对了,因为变量的值时变的,要及时输出

    比如:

            int one = 10 ;

            int two = 20 ;

            int three = 0 ;

            three=one+two;

            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;

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

             这样就对了,

    这个是我写的(参考):

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

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

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

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

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

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

            


    慕函数922...

    哦哦哦 非常感谢!

    2017-02-08 14:50:31

    共 1 条回复 >

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

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

1165172 学习 · 17581 问题

查看课程

相似问题