Unit 3: Boolean Expressions & if Statements
AP Computer Science AWhat you'll master in this unit
- •
- •
- •
- •
- •
- •
- •
The flow of control
java
int score = 85;
if (score >= 90) {
System.out.println("A"); // skipped
} else if (score >= 80) {
System.out.println("B"); // THIS runs
} else if (score >= 70) {
System.out.println("C"); // skipped
} else {
System.out.println("Below C"); // skipped
}
Key patterns at a glance
Logical operators
java
// AND — both must be true
if (age >= 16 && hasPermit) { ... }
// OR — at least one must be true
if (day.equals("Saturday") || day.equals("Sunday")) { ... }
// NOT — reverses the condition
if (!isRaining) { ... }
De Morgan's Laws
java
// These pairs are equivalent:
!(a && b) == (!a || !b)
!(a || b) == (!a && !b)