Professional Documents
Culture Documents
Operators Computer Pre Final Reviewer
Operators Computer Pre Final Reviewer
Operators Computer Pre Final Reviewer
Arithmetic Operators
Relational Operators
Addition Operator
-using +
Ex.
Ex.
1 + 3 inside parentheses
//The sum is : 4
Note: Parentheses is important, if we don’t use parentheses, the plus sign will be considered as a
concatenation operator; without the parentheses the output will be The sum is : 13. So to display the
expression correctly we use ().
Subtraction Operator
-using -
Ex.
int x = 3 - 1;
Ex.
Note: The + sign is considered as a concatenation operator, so the three will be concatenated to the string
[“The diff is : “], and after that you are subtracting one from the string that we will get, so this is why we will
get an error. To avoid error, you must use the parentheses.
Multiplication Operator
-using *
Ex.
int x = 3 * 2;
Ex.
Division Operator
-using /
Ex.
Ex.
int x = 6 / 2;
Ex.
-The result of the division of an integer and a double is a double (implicit casting)
Modulo Operator
-using %
Ex.
4 % 2 = 0 //4 is even
5 % 2 = 1 //5 is odd
Note: We are using modulo operator to find the remainder of the division by 2 and using the result we can
conclude is the number is even or odd
Ex.
int x = 6 % 4;
Ex.
OPERATOR PRECEDENCE
-all operations are done from left to right in the following order:
Ex.
2 * (1 + 5) - 12 / (4 + 2)
2 * (6) - 12 / (6)
12 - 2
10
So suppose that we have two values for example two numbers or two strings, anything, and we want to make
some comparisons
This is used to check if the two operand are equal, not equal, greater than, lesser than, greater than or equal,
lesser than or equal.
- Equality Operator: ==
- Inequality Operator: !=
Equal Operator: ==
-checks if the values of two operands are equal or not, if yes then condition becomes true
Ex.
Note: The parentheses are optional. Just used them to make the code more clear and readable
Not Equal Operators !=
-checks if the values of two operands are equal or not, if values are not equal then the condition becomes
true.
Checks of the values of the left operand is greater than the value of right operand, if yes then the condition
becomes true
Checks of the values of the left operand is greater than or equal to the value of right operand, if yes then the
condition becomes true
Checks of the values of the left operand is less than the value of right operand, if yes then the condition
becomes true
Checks of the values of the left operand is less than or equal to the value of right operand, if yes then the
condition becomes true.
Kung gusto pa nating magdagdag or magcheck pa ng another condition using and, or, not, pwede nating
gamitin yung Logical Operators.
Logical Operators
- is a symbol or word used to connect two or more expressions such that the value of the compound
expression produced depends only on that of the original expressions and on the meaning of the operator.
Common logical operators include AND, OR, and NOT.
Logical OR Operator ||
If any of the two operands are non-zero, then the condition becomes true.
Use to reserves the logical state of its operand. If a condition is true then Logical NOT operator will make
false.