为了账号安全,请及时绑定邮箱和手机立即绑定

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


正在回答

3 回答

int three = one + two ;

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

0 回复 有任何疑惑可以回复我~

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

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

其他的也一样

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Java入门第一季(IDEA工具)升级版
  • 参与学习       1162696    人
  • 解答问题       17548    个

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

进入课程

Java中的赋值运算符

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信