Basic Java Language: Difference between revisions

wikademia>Zchenyu
wikademia>Zchenyu
Line 146: Line 146:


=== Addition Operator '+' ===
=== Addition Operator '+' ===
The addition operator is different from the = operator. It does not set anything. You would need the = operator to do any setting.
The addition operator is different from the = operator in respect to the fact that it does not set anything. The addition operator returns the sum of the two values next to it.


If you want to you want to use the addition operator to add 6 to the value of ''a'', it would be used like this:
If you want to you want to use the addition operator to add 6 to the value of ''a'' and store that value back into ''a'', the following statement would be used:
<pre>a = a + 6;</pre>
<pre>a = a + 6;</pre>
Or you can use a shortcut in order to reach the same result as the above.
You could also use the plus-equals operator to achieve the same result:
<pre>a += 6;</pre>
<pre>a += 6;</pre>
There are shortcuts to all of the operators, which will be shown in the following sections.


=== Subtraction '-', Division '/' and Multiplication '*' Operators ===
=== Subtraction '-', Division '/' and Multiplication '*' Operators ===