if statement

An if loop will run if a certain condition is met (a>0, etc.).

int n = 5;

if (n>0){
    System.out.println("Greater than 0!"); //since 5>0, it is printing that.
}
Still greater than 0!

if-else statements

An if-else loop will run first test if something is true. If this is not true, it will perform another action, defined in the else portion of the if-else statement.

int n = 10;

if (n>15){
    System.out.println("Greater than 15!");
}
else{
    System.out.println("Less than (or equal to) 15!"); //since n=10, it is less than 15
}
Less than (or equal to) 15!

if-else-if statements

An if-elseif-else statement will first check if a certain condition is met. If that condition is not met, it will then check if another condition is met. If that condition is also not met, the final action in the else statement will be run.

int n = 12;
if (n>15){
    System.out.println("Greater than 15!");
}
else if (n>10){
    System.out.println("Greater than 10!");  //Since 12 is not greater than 15 but is greater than 10, it is printed that it is greater than 10. 
}
else{
    System.out.println("Less than or equal to 10!");
}
Greater than 10!

Switch Case

Switch case is basically where a condition is checked multiple times in multiple "cases". This can have many uses similar to that of if-elseif-else loops but can have different uses.

int n = 12;
if (n>15){
    System.out.println("Greater than 15!");
}
else if (n>13){
    System.out.println("Greater than 13!");  
}
else if (n>12){
    System.out.println("Greater than 12!");  
}
else if (n>11){
    System.out.println("Greater than 11!");  //Since 12 is not greater than 15 but is greater than 11, it is printed that it is greater than 10. 
}
else{
    System.out.println("Less than or equal to 10!");
}
Greater than 11!

This same process can be repeated using switch-case instead

int n = 12;
String output;
switch (n){
    case 9:
        output = "greater than 8";
        break;
    case 10:
        output = "greater than 9";
        break;
    case 11:
        output = "greater than 10";
        break;
    case 12:
        output = "greater than 11";
        break;

}
System.out.println(output);
greater than 11

De Morgan's Law

De Morgan's law states that Not (A and B) is the same as Not A or Not B. An example of this is I will not drink water and eat a table means the same thing is I will either not drink water or eat a table.

boolean A = true;
boolean B = true;
if (!(A && B)){
    System.out.println("A and B both are false");
}
else{
    System.out.println("A and B are true");
}
A and B are true
if (!A || !B){
    System.out.println("A and B both are false");
}
else{
    System.out.println("A and B are true");
}
A and B are true

As we can see, both of the if statements provide the same output, proving to us that De Morgan's law is true.