You are on page 1of 10

Q3W2

Operators
What is an Equality
Operator?
 The Equality operator (==) is the operator that provides a comparison of two or more operands. It returns
either True or False Value.

 String a = “hello”;

 String b = “hi”;

 String c = “hello”;

 Boolean Value

 Console.Writeline (a == b); False

 Console.Writeline (c == b); False

 Console.Writeline (c == “hello”); True


What is Relational Operator?
 The relational operators are often used to create a test expression that controls
program flow. This type of expression is also known as a Boolean expression
because they create a Boolean answer or value when evaluated.

 Operator symbols and/or names can vary with different programming languages. Most programming
languages use relational operators similar to the following:
 Operator Meaning

 < less than

 > greater than

 <= less than or equal to

 >= greater than or equal to

 == equality (equal to)

 != or <> inequality (not equal to)


 Examples:
 ( 9 == 5) // Evaluates to False.
 ( 9 > 4 ) // Evaluates to True.
 ( 5 != 2) // Evaluates to True.
 ( 9 >= 9 ) // Evaluates to True.
 ( 9 < 9 ) // Evaluates to False.

 Relational operators on expression comparison: Suppose that x=2, y=3 and z=6
 (x ==5) // Evaluates to false since x is not equal to 5.
 (x*y >=c) // Evaluates to true since (2*3 >= 6) is true.
 (y+4 > x*z) // Evaluates to false since (3+4 >2*6) is false.
 (x ==5) // Evaluates to false since x is not equal to 5.
Logical Operator
 Same with the relational operator, a logical operator also returns Boolean values as outputs. The
logical operators (&&) and (||) are used to when evaluating two expressions to obtain one relational
result.
 AND operator (&&) represents the Boolean logical operation AND. This operation results true if both its
operands are true, and false otherwise.

Input A Input B Output


A&&B
True True True

True False False

False True False

False False False


 The Operator or || represents the Boolean logical operation OR. This operation results true if either one of
tis two operands it true, thus being false only when both operands are false themselves.
A B A||B

True True True

True False True

False True True

False False False


 The operator NOT (!) simply provides the opposite Boolean Value

A !A

True False

False True
 1. Which of the following is a logical Operator?

 a. +

 b. =

 c. !

 d. /

 2. Which of the following is the Operator that produces Boolean values of two or more expressions?

 a. Relational

 b. Increment

 c. Operator precedence

 d. Arithmetic

 3. Write the correct expressions of the following statements:

 1. Write an expression that declares whether an integer is an odd number.

 2. Write a Boolean expression that declares whether a given integer is divisible by both 3 and 5, without
remainder

You might also like