Arithmetic and Relational Operators
Arithmetic and Relational Operators
Arithmetic and Relational Operators
– Arithmetic operators
– Relational operators
Arithmetic Operators
Operator Description
• + Addition
• - Subtraction
• * Multiplication
• / Division
• % Remainder after Division
• Examples of arithmetic expressions:
length * width
12.345 + 67.893 + 75.9004
• Rules of precedence dictate the order of evaluation. In this order, certain parts of the
expression gets executed first before others
• For arithmetic operators, the rules of precedence (or order of evaluation) are:
1. Expressions in parentheses
2. Multiplication and Division, from left to right
3. Addition and subtraction, from left to right
• In the expression,
answer = 4 + 6 * 2
answer = (4 + 6) * 2
• Java also has unary increment and decrement operators that increase or decrease the
value of a variable by 1
o Increment operator
o Decrement operator
• Example:
the expression,
count = count + 1;
could be written as
count ++;
Relational Operators