Once you click post assignment, learners in the selected class will immediately be able to see and complete this assignment

Back to Classroom

De Morgans Law

Java Basics Course

Engineers From These Top Companies and Universities Trust EXLskills

1M+ Professionals | 100+ Institutions

This is the EXLskills free and open-source Java Basics Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of essential coding proficiency.

Is this course FREE?

Yes, this a 100% free course that you can contribute to on GitHub here!

De Morgan's Law is helpful to remember for the AP exam because it will be useful with questions regarding boolean expressions. De Morgan's Law show how the NOT operator (!) can be distributed when it exists outside a set of parenthesis. Look below for a few examples of how De Morgan's Law works.

DeMorgansLawExample.java

package exlcode;
public class DeMorgansLawExample {
public static boolean exampleVariableOne = true;
public static boolean exampleVariableTwo = false;
public static void main(String[] args) {
// The two boolean expressions below are equal
if (!(exampleVariableOne && exampleVariableTwo)) {
System.out.println("The boolean expression is true");
} else {
System.out.println("The boolean expression is false");
}
if (!exampleVariableOne || !exampleVariableTwo) {
System.out.println("The boolean expression is true");
} else {
System.out.println("The boolean expression is false");
}
}
}

Some of the more common iterations for De Morgan's Law:

!(A && B) is the same as !A || !B

!(A || B) is the same as !A && !B

!(C > D) is the same as C <= D

!(C < D) is the same as C >= D

!(C >= D) is the same as C < D

!(C <= D) is the same as C > D

!(E == F) is the same as E != F

!(E != F) is the same as E == F

Remember, you do not have to limit yourself to two operands when you work with the "AND" operator and the "OR" operator. !(A && B && C) is the same as !A||!B||!C. For the iterations shown above, A and B have to be boolean values, C and D have to be numbers and E and F may be a variety of data types.