Boolean Logic & Conditional Statements
Applying De Morgan's laws, which is equivalent to this expression?:
!conditionA && !conditionB
conditionA && conditionB
Which of the following is the correct structure of an if statement?
if [condition] code block
if {condition} // code block
if (condition) { // code block }
if condition: code block
What happens when there is a return statement inside the conditional body of an if statement that evaluates to true?
The program throws an error.
The method restarts from the beginning.
The method continues executing the code after the if statement.
The method ends and returns a specific value.
Given an ArrayList named "data" containing integers in ascending order, which code snippet would correctly insert a new integer "num" while maintaining sorted order?
if(!data.contains(num)) {
for(int k=0; k<data.size(); k++) {
if(num < data.get(k)) {
break;
}
int idx = k+1 == data.size() ? k : k+1;
data.add(idx,num); break;
}
}
int j; for(j = data.size() - 1; j >=0 && num < data.get(j); j--) {} data.add(j + 1, num);
int i = 0; while(i < data.size() && num > data.get(i)) { i++; } data.add(i, num);
for(int elem : data) { if(num <= elem) { int index = data.indexOf(elem); data.add(index, num); break; } }
In terms of Java's built-in control structures for managing errors, what does unchecked mean regarding exceptions?
Unchecked exceptions are not required to be declared or handled by programmers.
They can only be resolved using custom methods instead standard language features.
These represent syntax mistakes like misspelling keywords variables names.
Only do occur during compile-time thus making easier detect resolve early stages development process.
What is an advantage of using nested if statements instead of consecutive if statements?
They allow sequential checks where each condition depends on the previous one being true.
Nested if statements execute faster due to reduced computational complexity.
They can handle multiple else clauses associated with each conditional check.
They avoid the need for any logical operators such as AND (&&) or OR (||).
What would be the result of executing the following code segment if temp
equals -15?
Cold
Freezing
Normal
Warm

How are we doing?
Give us your feedback and let us know how we can improve
In what way can altering the order of boolean expressions within an if-else chain affect program efficiency without changing output?
Reordering boolean expressions has no effect on program efficiency or output due to compiler optimization techniques.
Ordering conditions from most likely to least likely to be true can reduce average runtime by short-circuit evaluation.
Interspersing System.out.println statements between conditions improves debugging but impacts neither speed nor output consistency.
Alphabetizing variable names inside boolean expressions enhances readability but does not influence execution time or results.
How might including else-if ladders instead separate if blocks affect performance logic handling multiple conditions?
Including separate mandatory pause points between decisions allowing CPU cool down cycles, though it doesn't actually contribute to the effectiveness of code execution
Enabling easier modification and addition of subsequent conditions for future maintenance tasks, easing understanding but impacting immediate runtime efficiency
Allowing insertion of additional print statements for debugging purposes, which although useful for development, does inherently slow down the main execution path
It increases potential to execute unnecessary comparisons after an already matching condition has been found, leading to greater overall ineffectiveness compared to using a consolidated else-if ladder
In a simple Java program, what does an if
statement do?
Executes a block of code for each item in an array or collection.
Exits from a loop or method prematurely.
Repeats a block of code while a condition is true.
Checks a condition and executes a block of code if that condition is true.