

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Boolean Expression - Answer - A boolean expression evaluates to either true or false using relational operators to compare values. Relational Operator: == - Answer - Checks if two values are equal. Relational Operator: != - Answer - Checks if two values are not equal. Relational Operator: > - Answer - Checks if the left value is greater than the right. Relational Operator: < - Answer - Checks if the left value is less than the right. Relational Operator: >= - Answer - Checks if the left value is greater than or equal to the right. Relational Operator: <= - Answer - Checks if the left value is less than or equal to the right. Logical Operator: && (AND) - Answer - Returns true only if both sides are true. Logical Operator: || (OR) - Answer - Returns true if at least one side is true. Logical Operator:! (NOT) - Answer - Reverses the truth value of a condition. if / else / else if Structure - Answer - Conditions are checked from top to bottom; the first match executes, and others are skipped. Multiple if vs. Nested if Statements - Answer - Separate if statements run independently; nested if statements depend on prior conditions. Nested if Statements - Key Points - Answer - Use when one condition depends on another. Each else matches the closest unmatched if. Indentation shows structure. Arithmetic Conditions and % Operator - Answer - % (modulus) returns the remainder. Useful for checking even/odd, multiples, or randomized conditions. Variable Updates Inside if Blocks - Answer - Changes to variables inside if blocks affect later code and should be tracked carefully. Nested Logic with Boolean Variables - Answer - Complex conditions can combine multiple boolean expressions using logical operators. Comparing Strings in Java - Answer - Use .equals() or .compareTo() instead of == to compare string values.
String Comparison: == - Answer - Checks if two string references point to the same object in memory. String Comparison: .equals() - Answer - Checks if two strings have the same characters in the same order. String Comparison: .compareTo() - Answer - Returns 0 if strings are equal; compares based on alphabetical order. Combining String Comparisons and Logic - Answer - Use nested conditions to check multiple string and value conditions together. Translating English to Boolean Logic - Answer - Convert everyday language into boolean expressions using relational and logical operators. English to Logic: 'a is not zero or b is zero' - Answer - a != 0 || b == 0 English to Logic: 'a is positive and b is negative' - Answer - a > 0 && b < 0 English to Logic: 'c is even' - Answer - c % 2 == 0 English to Logic: 'b between 50 and 100 inclusive' - Answer - b >= 50 && b <= 100 English to Logic: 'a is the smallest of three' - Answer - a < b && a < c Return Statements vs. Print Statements - Answer - return sends back a value to the caller; print outputs to the console but returns nothing. De Morgan's Law: !(A && B) - Answer - !A || !B De Morgan's Law: !(A || B) - Answer - !A && !B