Class Notes (1,100,000)
US (490,000)
UC (700)
IT (10)
Lecture 3

IT 1090C Lecture 3: Boolean Variables

Information Technology
Course Code
IT 1090C
Wulf Tom

This preview shows half of the first page. to view the full 2 pages of the document.
3.7 Boolean Variables
A Boolean variable is often called a flag because it can be either up (true) or down (false)
Boolean is a Java data type
Boolean failed= true;
Can be either true or false
Boolean Operators: && and I I
They combine multiple conditions
&& is the and
I I is the or
Combining two conditions is often used in range checking
Is a value between two other values?
Both sides of the and
must be true for the result to be true
If only one of two conditions need to be true
Use a compound conditional with an or:
If either is true
The result is true
If you need to invert a boolean variable or comparison, combine conditions.
3.8 Input Validation
Accepting user input is dangerous
Consider the Elevator program:
The user may input an invalid character or value
Must be an integer
Scanner can help
True if integer
False if not
The range check value
We expect a floor number to be between 1 and 20
Not 0, 13 or greater than 20
You're Reading a Preview

Unlock to view full version