AP® Computer Science A glossary
De Morgan's laws
Also called: De Morgan's law
Course: AP® Computer Science A Shows up in: Unit 2: Selection and Iteration
Rules that create equivalent Boolean expressions: !(a && b) is equivalent to !a || !b, and !(a || b) is equivalent to !a && !b.
Appears in the course and exam description (CED): 2.6.A.2
Negate each part and switch && with ||. When the parts are comparisons, negate each one: the opposite of x > 5 is x <= 5.
int temp = 24;
boolean isRaining = false;
System.out.println(!(temp > 30 || isRaining));
System.out.println(temp <= 30 && !isRaining);
Output:
true
true Learn it properly, with a checkpoint 2.6 Comparing Boolean Expressions