0% found this document useful (0 votes)
4 views24 pages

Booleans, Logical and Comparison Operators

The document explains the importance of booleans, comparison, and logical operators in Java programming, emphasizing their role in decision-making. It outlines lesson objectives including creating boolean variables, using logical operators (AND, OR, NOT), and comparison operators (<, <=, >, >=, ==, !=). Additionally, it introduces a Boolean Game as an engaging way to reinforce the concepts learned.

Uploaded by

aneesammari1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views24 pages

Booleans, Logical and Comparison Operators

The document explains the importance of booleans, comparison, and logical operators in Java programming, emphasizing their role in decision-making. It outlines lesson objectives including creating boolean variables, using logical operators (AND, OR, NOT), and comparison operators (<, <=, >, >=, ==, !=). Additionally, it introduces a Boolean Game as an engaging way to reinforce the concepts learned.

Uploaded by

aneesammari1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Booleans,

Comparison and
Logical Operators
in Java
Computing
Why are booleans
important in Java?
Driving Question
3

“PDN
In pairs come up with
different sets of booleans.
Using binary numbers,
determine the values of the
booleans.


4


Booleans, Comparison
and Logical Operators
are very important in any
programming language and
they help us take decisions
based on certain conditions.


5

Lesson objectives

▰ Create boolean variables to represent meaningful yes/no values


▰ Print out the value of a boolean variable
▰ Describe the meaning and usage of each logical operator: OR (||), AND (&&),
and NOT (!)
▰ Construct logical statements using boolean variables and logical operators
▰ Explain the meaning of each of the comparison operators (<, <=, >, >=, ==, !=)
▰ Create programs using the comparison operators to compare values
▰ Predict the boolean result of comparing two values
▰ Print out the boolean result of comparing values
6

Let us get started.


7

Booleans

How do we write code that tells us whether a user is


logged in to our program?
Booleans are the solution to these questions. A
boolean refers to a value that is true or false.
Those are the only values of a boolean expression,
and these are useful if we want to check if
something is true or false.
8

Booleans
Boolean is a system of logical thought that creates
true or false statements. In computing, a Boolean is
a result that can only be true or false.
Boolean expressions use operators like AND, OR,
XOR, and NOT to compare values and return a true
or false result. For example, the AND operator
requires both terms to be in each item returned.
The OR Boolean only requires one or the other.
9

What do you think the


following code print?
10

Comparison Operators

Comparison operators let us compare two values.


Using comparison operators in programming is
similar to math in that less than <, greater than >,
less than or equal to <=, and greater than or equal
to >= are the same. The differences are that
operators for equal to are == and not equal are !=.
Using comparison operators allows our program to
make decisions.
11

Comparison Operators
12

What do you think the


following code print?
13

What do you think the


following code print?
14

What do you think the


following code print?
15

Logical Operators

Logical operators allow us to connect or modify


Boolean expressions.
Logical operators can be used in combination.
With these logical operators, we can construct
logical statements such as “I go to sleep when I am
tired OR it’s after 9pm”, “I wear flip flops when I am
outside AND it is NOT raining”
16

Logical Operators
17

The AND (&&) Operator

x y x && y
true true true
true false false
false true false
false false false
18

What do you think the


following code print?
19

The OR (||) Operator

x y x || y
true true true
true false true
false true true
false false false
20

What do you think the


following code print?
21

The NOT (!) Operator

x !x
true false
false true
22

What do you think the


following code print?
23

Exit Ticket

Let us play the Boolean Game, rules are as follows:


1. Play the game for 1 minute in the first round, only
half the learners with the highest score can move
on to the next round.
2. Play again but this time for 45 seconds, then 30
seconds, then 15 seconds,
3. Finally the people left will play for 1 minute again
and the person with the highest score is the
winner.
24

References

www.w3schools.com
www.codehs.com
https://booleangame.com/

You might also like