Operators
Operators
Assignment operators are used in Java to assign values to variables. For example,
int age;
age = 5;
The assignment operator assigns the value on its right to the variable on its left. Here, 5 is assigned
to the variable age using = operator.
Arithmetic Operators
Arithmetic operators are used to perform mathematical operations like addition, subtraction,
multiplication etc.
Operator Meaning
- Subtraction Operator
* Multiplication Operator
/ Division Operator
% Remainder Operator
Unary Operators
Operator Meaning
+ Unary plus (not necessary to use since numbers are positive without using it)
The equality and relational operators determines the relationship between two operands. It checks
if an operand is greater than, less than, equal to, not equal to and so on. Depending on the
relationship, it results to either true or false.
&& (Logical AND) Returns the value if both the conditions are true otherwise
returns zero.
Ternary Operator
The conditional operator or ternary operator ?: is shorthand for if-then-else statement. The syntax
of conditional operator is:
variable = Expression ? expression1 : expression2