Java
Java
Java
Most common operators that you'll use is the simple assignment operator "=“,
it assigns the value on its right to the operand on its left:
number = number * 2;
System.out.println(number);
number = number / 2;
System.out.println(number);
number = number + 8;
THE UNARY OPERATORS
The unary operators require only one operand; they perform various operations such as
incrementing/decrementing a value by one, negating an expression, or inverting the value of a
Boolean.
+ Unary plus operator; indicates positive value (numbers are positive without this, however)
- Unary minus operator; negates an expression
++ Increment operator; increments a value by 1
-- Decrement operator; decrements a value by 1
! Logical complement operator;
inverts the value of a boolean
THE EQUALITY AND RELATIONAL
OPERATORS
Operator
The equality and relational operators determine if one operand is == Equal to
greater than, less than, equal to, or not equal to another operand. != Not equal to
Also known as Comparison Operators > Greater
int number1 = 1; >= Greater than or
equal to
int number2 = 2;
< Less than
System.out.println(number1 == number2); <= Less than or
System.out.println(number1 != number2); equal to
System.out.println(number1 > number2);
System.out.println(number1 < number2);
System.out.println(number1 <= number2);
THE CONDITIONAL OPERATORS
Operators have a well-defined precedence which determines the order in which they
are evaluated
Arithmetic operators with the same precedence are evaluated from left to right, but
parentheses can be used to force the evaluation order
OPERATOR PRECEDENCE
What is the order of evaluation in the following expressions?
a + b + c + d + e a + b * c - d / e
1 2 3 4 3 2 4 1
a / (b + c) - d % e
2 1 4 3
int a=3,b=3,c=3,d=3,e=3;
a / (b * (c + (d - e))) int f = a + b * c - d / e;
System.out.println(f);
4 3 2 1
OUTPUT????
OPERATOR PRECEDENCE
The operators in the following table are listed according to precedence order. The closer to the top of the
table an operator appears, the higher its precedence
Operators Precedence
postfix expr++ expr--
unary ++expr --expr +expr -expr ~ !
multiplicative */%
additive +-
shift << >> >>>
relational < > <= >= instanceof
equality == !=
bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
logical AND &&
logical OR ||
ternary ?:
assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=