Module 03: Boolean Expressions and if Statements Flashcards
What will this code return given checkMethod(false, true)?
-1
What will this method call output given yesOrNo(true)?
“Yes”
Given the following call, what value would be returned for findTheMiddle(2110890125)?
89
Which expression is true?
- true && !true
- !false || !true
- true && false
- false || false || !true
- !false || !true
What will this code output?
- Hello Karel
- Hello Karel
Second if statement! - Second if statement!
- This program will print nothing
- Second if statement!
What will this program print if the value of grade is 80?
C
What will the values of x and y be after this code segment runs?
- x = 100
y = 200 - x = 99
y = 100 - x = 101
y = 201 - x = 99
y = 199
- x = 99
y = 199
A company uses the following table to determine pay rate based on hours worked:
Which of the following test cases can be used to show that the code does NOT work as intended?
- calculateRate(35);
- calculateRate(40);
- calculateRate(45);
- calculateRate(55);
- calculateRate(40);
Assuming a and b are properly initialized boolean values, which expression would be equivalent to the following:
!(a && b)
- a || b
- !(a || b)
- !a && !b
- !a || !b
- !a || !b
A student is trying to determine if the following two expressions are equivalent.
A. x && (!x || y)
B. x && !(x || !y)
What values of x and y would prove that the expressions are NOT equivalent?
x = true y = true
x = true y = false
x = false y = true
x = false y = false
x = true y = true
Given a, b, and c are properly initialized boolean values, what values would make the following expression false?
(a || b) || (b || c) || (!a || b);
- a and b must be different values
- a must be false
- b and c must have the same values
- Nothing. The expression will always be true.
- Nothing. The expression will always be true
In order to ride the zip line, you need to be at least 12 years old and weigh at least 75 pounds, but no more than 300 pounds.
Which of the following code segments would correctly determine if you can ride the zip line?
I and II only
I only
II only
III only
I, II, III
II only
What will the following code output when executed?
BC
The following code is intended to return only even numbers. If an even number is passed to the method, it should return that number. If an odd number or zero is passed, it should return the next highest even number.
Does the code work as intended?
- Yes.
- No, the mod function on line 3 should read number % 2 == 1 to find even numbers.
- No, the else if on line 7 and the else on line 11 should just be if statements.
- No. Zero will get returned on line 5 and not make it to line 7.
- No. Zero will get returned on line 5 and not make it to line 7
Given the following statements, which options will print true?
- String ursa = new String(“2849”);*
- String major = new String(“2849”);*
I. System.out.println(ursa.equals(major));
II. System.out.println(ursa == major);
III. System.out.println(ursa.equals(“2849”));
IV. System.out.println(major == “2849”);
I, II, III, and IV
IV only
I, III, and IV only
II and IV only
I and III only
I and III only