Using boolean logic in Java Flashcards

1
Q

what two values can a boolean expression have?

A

true or false.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what is the difference between == and .equals

A

.equals is used to compare two strings it compares the values, == compares the memory address of two strings and not the actual values

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

when does this comparison operator return? ==

A

this will return true if both sides are true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

what does this comparison operator return? !=

A

this will return true if expression is not equal.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what does this comparison operator return? < or <=

A

the left side of the comparison must be true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what does this comparison operator return? > or >=

A

the right side of the comparison must be true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

what does this logical operator mean? !

A

not

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

what does this logical operator mean? &&

A

and

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what does this logical operator mean? ||

A

or

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is short circuiting?

A

short-circuiting is the process of not having to evaluate the whole expression to know what the result is.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

how many statements does a simple conditional statement have?

A

one

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

what conditions does a single branching conditional statement have to meet?

A

must use the else statement, will only run if false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what conditions does a multiple branching conditional statement have to meet?

A

must use with an else if statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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”)
}

A

simple conditional statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what type of conditional statement is this

boolean isHead = false;
if (isHead) {
System.out.println(“doing things”);
} else {
System.out.println(“not doing things”);
}

A

single branching conditional statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what type of conditional statement is this

String occassion = “Birthday”;
if (occassion.equals(“work”) {
System.out.println(“no”);
} elseif (occassion.equals(“Birthday”) {
System.out.println(“Happy Birthday”);
} else {
System.out.println(“no”);
}

A

multiple branching conditional statement