Lesson 8 | Using numeric operators |

Objective | Use Java's commonly-used Numeric Operators |

Numeric operators are used to manipulate numbers, and are divided across three different types: unary, binary, and relational.

Unary operators operate on a single number, with the two most commonly used unary operators being ++ and --.

These operators are used to increment or decrement a number by 1.

Unary operators in an expression can be used as either prefix or postfix operators. A prefix operator is applied before the expression is evaluated, while a postfix operator is applied after the expression is evaluated.

Following are the commonly used binary operators:

Unary operators operate on a single number, with the two most commonly used unary operators being ++ and --.

These operators are used to increment or decrement a number by 1.

Unary operators in an expression can be used as either prefix or postfix operators. A prefix operator is applied before the expression is evaluated, while a postfix operator is applied after the expression is evaluated.

Following are the commonly used binary operators:

- Less-than: Compares two values and returns true if the first is less than the second.
- Greater-than: Compares two values and returns true if the first is greater than the second
- Less-than-or-equal-to: Compares two values and returns true if the first is less than or equal to the second.
- Greater-than-or-equal-to: Compares two values and returns true if the first is greater than or equal to the second.
- Equal-to: Compares two values and returns true if they are equal
- Not-equal-to: Compares two values and returns true if they are not equal.

Relational operators are used to check one condition. You can use these operators to determine whether a primitive value is equal to another value or whether it is less than or greater than the other value. These relational operators can be divided into two categories:

Examine the following code:

The second category of operators is covered in the following section.

- Comparing greater (>, >=) and lesser values (<, <=)
- Comparing values for equality (==) and nonequality (!=)

Examine the following code:

int i1 = 10; int i2 = 20; System.out.println(i1 >= i2);false

long long1 = 10; long long2 = 20; System.out.println(long1 <= long2);true

The second category of operators is covered in the following section.