运算符+ = vs = +之间有什么区别 [英] What is the difference between the operators += vs =+
本文介绍了运算符+ = vs = +之间有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚意识到我正在使用= +而不是运算符+ =而我的程序正在做各种奇怪和意想不到的事情。 Eclipse没有给我任何类型的错误,所以我认为= +是一个合法的运算符,但在我的书中没有提到它。
I just realized that I was using =+ instead of the operator += and my program was doing all sorts of weird and unexpected things. Eclipse didn't give me an error of any kind so I assume that =+ is a legitimate operator but there is no reference to that in my book.
我的问题是= +做什么,如果有的话,在什么情况下你会使用它?
My question is what does =+ do if anything and under what circumstances would you use it?
推荐答案
+=
添加AND赋值运算符,它将右操作数添加到左操作数并将结果赋给左操作数。
Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand.
示例:
int i =1;
int j=2;
i += j;
System.out.println(i); //prints 3
= +与=
让我们举例说明
int i =1;
int j=2;
i =+ j;
System.out.println(i); //prints 2 only
这篇关于运算符+ = vs = +之间有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文