Using boolean logic in Java Flashcards
what two values can a boolean expression have?
true or false.
what is the difference between == and .equals
.equals is used to compare two strings it compares the values, == compares the memory address of two strings and not the actual values
when does this comparison operator return? ==
this will return true if both sides are true
what does this comparison operator return? !=
this will return true if expression is not equal.
what does this comparison operator return? < or <=
the left side of the comparison must be true
what does this comparison operator return? > or >=
the right side of the comparison must be true
what does this logical operator mean? !
not
what does this logical operator mean? &&
and
what does this logical operator mean? ||
or
what is short circuiting?
short-circuiting is the process of not having to evaluate the whole expression to know what the result is.
how many statements does a simple conditional statement have?
one
what conditions does a single branching conditional statement have to meet?
must use the else statement, will only run if false
what conditions does a multiple branching conditional statement have to meet?
must use with an else if statement.
what type of conditional statement is this
int number = 10;
if (number > 5) {
System.out.println(“Will run”);
}
if (number > 10) {
System.out.println(“will not run”)
}
simple conditional statement
what type of conditional statement is this
boolean isHead = false;
if (isHead) {
System.out.println(“doing things”);
} else {
System.out.println(“not doing things”);
}
single branching conditional statement