java / beginner
Snippet
Basic Conditional Logic
The 'if-else' statement allows your program to make decisions based on conditions. If the condition in the parentheses is true, the first block executes; otherwise, the else block runs.
snippet.java
java
1
2
3
4
5
6
7
int temperature = 20;if (temperature > 25) {System.out.println("It is hot outside.");} else {System.out.println("The weather is fine.");}
Breakdown
1
if (temperature > 25) {
Checks if the temperature variable is greater than 25.
2
System.out.println(...);
Prints a message to the standard output console.