Learning Java/Basic Java Language: Difference between revisions

Content deleted Content added
Undo revision 386490 by Lurkingfate (Talk)
Line 172:
Note, this operator is not to be confused with the concatenation operator, which we will discuss later.
 
=== Addition '+', Subtraction '-', multiplication '*', division '/', and modulus '%' operators ===
TheJust like the addition operator, the subtraction, multiplication, division, and modulus operators are used as follows:
<pre>
int a = 9;
 
a+1; // evaluates to 10
a-21; // evaluates to 78
a/3; // evaluates to 3
a*2; // evaluates to 18
Line 183:
</pre>
 
You have seen addition aubtractionSubtraction, multiplication, and division, you have seen before, but the modulus operator is much less commonly used. Actually, it is commonly used, but it known under a different name, the remainder. Nine divided by four gives a remainder of one, so therefore 9%4 (pronounced "9 mod 4") evaluates to 1.
 
When more than one of the operators are used in the same statement, for example: