Cari Blog Ini

20 November 2010

IT - Numeric Operator

Numeric Operator

* 4 Real Number Data types in Java : byte, short, int, and long
* 2 Decimal Number Data types in Java : float, and double.
* Using Double Decimal is more accurate than float
* The result of two Real Number division produce Real Number
* 5/2 = 2 (not 2.5), the result produce 2 instead of 2.5 due to truncation.
* `%’ is an operator to calculate remainder/modulo from a division.
This operator can be used with positive/negative number or decimal number.



Example :
10%7 = 3
6 % 7 = 6
-7 % 3 = -1
-12 % 4 = 0
20 % -13 = 7
-26 % -8 = -2

* Let 20 % -13 = 7
20 = dividend
-13 = divisor
7 = result
If a dividend is negative, the result of modulo/remainder operation is negative. 
Modulo/remainder is important in programmig.

Example :
Algorithm for determining even/odd number.
Search algorithm for finding day in Calendar.


Assignment Statements



Assignment Expressions


Aritmathic Expressions

* Execution priority is * and / as highest, + and – as lowest. It will executed after parentheses.
* If there is more than one Arithmetic Expression at the same level,
the highest priority is from the left to the right which is lowest priority.