Real-Life Examples
This example shows how you can use if..else to “open a door” if the user enters the correct code:
Example
int doorCode = 1337;
if (doorCode == 1337) {
System.out.println("Correct code. The door is now open.");
} else {
System.out.println("Wrong code. The door remains closed.");
}
This example shows how you can use if..else to find out if a number is positive or negative: Continue reading Java If … Else Examples