Basic Java Language: Difference between revisions
| Line 100: | Line 100: | ||
===Subtraction -, Division / and Multiplication * Operators=== | ===Subtraction -, Division / and Multiplication * Operators=== | ||
Just like the addition operator, the Subtraction, Division, and Multiplication operators are used as follows: | |||
<pre> | |||
int a; | |||
a = a-1; | |||
a = a/1; | |||
a = a*1; | |||
</pre> | |||
The result of "a" in each example would be simply | |||
1st a - "a" minus 1 | |||
2nd a - "a" divided by 1 | |||
3rd a - "a" multiplied by 1 | |||
When all of the operators are used at once, for example: | |||
<pre> | |||
int a, b, c, d; | |||
a = a-b/c*d; | |||
</pre> | |||
Then you would use the order or operations, otherwise known as PEMDAS, to find the result of "a"; which would be: | |||
<pre> | |||
a = a - (b/c)d | |||
or | |||
b | |||
a = a - --- | |||
(c*d) | |||
(either way the result is the same) | |||
</pre> | |||
Or if you prefer actual numbers, it would look like so: | |||
<pre> | |||
int a = 1; | |||
int b = 2; | |||
int c = 2; | |||
int d = 1; | |||
a = 1-2/2*1; | |||
thus: | |||
a = 1 - 1 | |||
or | |||
a = 0; | |||
</pre> | |||
'''More comming soon''' | '''More comming soon''' | ||
[[Topic:Java|Back to Java Main Page]] | [[Topic:Java|Back to Java Main Page]] | ||