Boolean Expressions and If-Else Statements
My explanation of conditional statements, booleans, and De Morgan's law
If Statements and other Conditionals
Will check boolean value and execute based on whether the conditions is met or not. The If statement is used to check the first condition and if that requirement is met, then it will execute the command. The else statement follows after and executes another command in case the original requirement for the if statement was not met. The else if comes in between and shows another condition to meet and will run if it is met.
if (score >= 90) {
grade = 'A';
} else if (score >= 80) {
grade = 'B';
} else if (score >= 70) {
grade = 'C';
} else if (score >= 60) {
grade = 'D';
} else {
grade = 'F'
}
boolean cat = true;
boolean spotted = false;
if (!(cat && spotted)){
System.out.println("You have a spotted cat");
} else{
System.out.println("Your cat is not spotted");
}