if statement runs the code contained inside if the condition inside of the statement is satisfied

// set up variable
boolean lights = true;

// if the lights is set to true, it will print the statement
if(lights == true){
    System.out.println("The lights are on!");
}

// another way of doing the same thing using boolean expressions
if(lights){
    System.out.println("The lights are on!");
}
The lights are on!
The lights are on!

if-else statement runs the if statment first, but if that condition is not met, it will run whatever is in the else statement

// set up variable
boolean lights = false;

// if the lights is set to true, it will print the statement. Else the lights are off.
if(lights == true){
    System.out.println("The lights are on!");
}
else{
    System.out.println("The lights are off!");
}

// another way of doing the same thing using boolean expressions (if lights are not false, meaning they are true)
if(lights != false){
    System.out.println("The lights are on!");
}
else{
    System.out.println("The lights are off!");
}
The lights are off!
The lights are off!

if-elseif-else first checks to see if the if statement condition is met. If not, it will go through all else ifs and check until one of those conditions are met. If neither the if and else if statements are met, it will run the else statement.

// Setting variables to demonstrate if, else if, and else.
boolean lights = true;
boolean fan = true;

// First checks if statement 
if(lights && !fan){
    System.out.println("The lights are on and the fan is off!");
}
// Goes down else ifs
else if(!lights && fan){
    System.out.println("The lights are off and the fan is on!");
}
else if(!lights && !fan){
    System.out.println("The lights are off and the fan is off!");
}
else if(!lights || !fan){
    System.out.println("Either the lights are off or the fan is off!");
}
// If none of the above run, else block will run
else{
    System.out.println("Both the lights and fan must be on!");
}
Both the lights and fan must be on!

De Morgan's Law shows how we can remove an && statement or remove an || statement. It's the way of creating equivalent statements by switching the && or || and distributing the ! sign if you need.

// First demonstration
System.out.println("First Demonstration:");
boolean lights = true;
boolean fan = true;

// first way
if(!(lights && fan)){
    System.out.println("Something is off!");
}

// second way
if(!lights || !fan){
    System.out.println("Something is off!");
}

// if one of the variables is set to true
else{
    System.out.println("Everything is on!");
}



// Second demonstration
System.out.println("Second Demonstration:");
boolean sink = false;
boolean shower = false;

// first way
if(!(sink || shower)){
    System.out.println("Everything is off!");
}

// second way
if(!sink && !shower){
    System.out.println("Everything is off!");
}

else{
    System.out.println("Something is on!");
}



// third demonstration
System.out.println("Third Demonstration: ");
int num1 = 3;
int num2 = 10;

// first way
System.out.println(!(num1 == 5 && num2 != 5));
// second way
System.out.println(num1 != 5 || num2 == 5);


// Weird and confusing
System.out.println("Overly complicated for no reason:");
if((lights || !fan) || (sink && shower)){
    System.out.println("Either lights are on or fan is off, or sink and shower are on.");
}
First Demonstration:
Everything is on!
Second Demonstration:
Everything is off!
Everything is off!
Third Demonstration: 
true
true
Overly complicated for no reason:
Either lights are on or fan is off, or sink and shower are on.