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
What will the final values of x and y be if their initial values are:
x = 12;
y = 5;

x = 24 y = 20
Assuming weekday and holiday are properly initialized booleans, which expression would be equivalent to the following:
!(!weekday || holiday)
- weekday || !holiday
- weekday && !holiday
- !weekday && !holiday
- !(weekday || !holiday)
- weekday && !holiday
The following method is designed to return true if the passed phrase contains either the word cat or dog.
Which of the following test cases can be used to show the code does NOT work as intended?
- containsPet(“I have a dog.”);
- containsPet(“I don’t have pets.”);
- containsPet(“I can catch fish.”);
- containsPet(“My dog caught my cat”);

- containsPet(“I can catch fish.”);
What will the following code output when executed?

Long Word
Medium Word
What values for x and y will cause the program to execute the /* missing code */?

x = 12 y = 12
Look at the following code and explain what the result is for each print statement and why.

System.out.println(s1 == s2);
// True: s2 is refering to the same object as s1, so the “==” operator will return as true since the two strings are referring to the same address.
System.out.println(s1 == s3);
// False: s1 is a string while s3 is an object, so they are not referring to the memory address
System.out.println(s4 == s3);
// False: since s4 is a new string - though it is referring to the value of s3 - it is allocated its own address; hence they are not the same memory location and therefore not equal.
System.out.println(s4 == s5);
// True: since s5 is referring to the memory of s4 so the address comparison is true (compared to the line above where the content was equal but not the address)
System.out.println(s1.equals(s2));
// True: the value is true since s1 and s2 have the same content so they content is equal.
System.out.println(s1.equals(s3));
// True: though one is a string and one is an object, both have the same content, notably “Hello,” so they will be true through a content comparison
What are rational operators?
==, !=, , <=, >=
Allow for the comparison or primitive type values.
Results are stored as Boolean values
What are Boolean operators?
Booleans can also use Relational Operators to store true/false information
Relational Operators are used to comparing the values of two expressions
What is an equality operator?
==
Returns true is both the operators are referring to the same object


