Page 316 - CITS - Computer Software Application -TT
P. 316
COMPUTER SOFTWARE APPLICATION - CITS
Output : num1 = 10 num2 = 20
The sum = 30
Assignment Operators
• = (Assignment): Assigns the value of the right operand to the left operand.
• += (Addition Assignment): Adds the right operand to the left operand and assigns the result to the left
operand.
• -= (Subtraction Assignment): Subtracts the right operand from the left operand and assigns the result to the
left operand.
• *= (Multiplication Assignment): Multiplies the left operand by the right operand and assigns the result to the
left operand.
• /= (Division Assignment): Divides the left operand by the right operand and assigns the result to the left
operand.
• %= (Modulus Assignment): Computes the modulus of the left operand and the right operand and assigns the
result to the left operand.
Example: int x = 10;
x += 5; // x is now 15
x -= 3; // x is now 12
x *= 2; // x is now 24
x /= 4; // x is now 6
x %= 3; // x is now 0
Relational Operators
• == (Equal to): Checks if two operands are equal.
• != (Not equal to): Checks if two operands are not equal.
• < (Less than): Checks if the left operand is less than the right operand.
• > (Greater than): Checks if the left operand is greater than the right operand.
• <= (Less than or equal to): Checks if the left operand is less than or equal to the right operand.
• >= (Greater than or equal to): Checks if the left operand is greater than or equal to the right operand.
Example
int num1 = 10, num2 = 20;
boolean isEqual = (num1 == num2); // false
boolean isNotEqual = (num1 != num2); // true
boolean isLessThan = (num1 < num2); // true
boolean isGreaterThan = (num1 > num2); // false
Logical Operators
• && (Logical AND): Returns true if both operands are true.
• || (Logical OR): Returns true if at least one operand is true.
• ! (Logical NOT): Returns the opposite boolean value of the operand.
Example
boolean isTrue = true, isFalse = false;
boolean result1 = isTrue && isFalse; // false
303
CITS : IT&ITES - Computer Software Application - Lesson 78 - 84
78