Unit 3: Boolean Expressions & if Statements Flashcards
Under what conditions does an if statement execute?
An if statement executes when the boolean expression within the parentheses is true.
How do you compare Strings?
You compare strings through the “.equals()” method, which returns a boolean expression.
What is the difference between = and == ?
= is used to assign values
== is used when checking equality
Which of the following symbols is the “not equal” symbol?
a) =!
b) ==
c) !=
d) !!
c) !=
Under what conditions does an else statement execute?
Else statements execute if the initial boolean expression evaluates to false
What is the purpose of an else if statement?
Else if statements allow us to incorporate additional conditions to if-else statements
Will it return true or false?
!(true && false) || (false && false)
true
What are the 3 logical operators?
NOT !
AND &&
OR ||
What is the not operator?
!(not) evaluates a condition to the opposite boolean value
Are both of these equivalent?
p && !q || !p && q
p || q) && (!p || !q
yes
What is the and operator?
The &&(and) evaluates whether all conditions are true
What is the or operator?
|| (or) evaluates whether one condition is true
Do boolean operators also have an order of operations?
Yes!
What would the output be for the following code
double x = 15.0/11.0;
System.out.println(11.0*x == 15.0);
False
Is this statement true?
!(a && b) == !a or !b
True statement, De Morgan’s law