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

Java中的赋值运算符

自己做了一遍运行错误,于是放到Eclipse上运行发现是int there = one + two; there前没引用类型,有两点不能理解的是减等于和除等于和模等于的规律。。求解


public class HelloWorld{

    public static void main(String[] args) {

int one = 10 ;

        int two = 20 ;

        int three = 0 ;

        int there = one + two;

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

        there += one;

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

        there -= one;

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

        there *= one;

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

        there /= one;

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

        there %= one;

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


提问者:慕仙7327719 2018-01-25 22:03

个回答

  • 慕仙4346529
    2018-01-31 12:00:12

    int three = one + two ;

    把前面那个int去掉,已经定义过three类型了,不用重新定义了

  • 慕粉3841666
    2018-01-25 22:33:23


    运行好像没问题啊,代码应该也没问题,除了three这个变量没用到,估计是打错了吧,不过第二个变量there也定义了,所以没问题。

    three -= one;    等价于    three = three - one;

    其他的也一样