capypad
0 day streak
java / beginner
Snippet

Conditional Logic with If-Else

The 'if' statement allows you to execute code only if a specific condition is true. The 'else' block provides an alternative if the condition is false.

snippet.java
java
1
2
3
4
5
6
int score = 85;
if (score >= 50) {
System.out.println("Passed!");
} else {
System.out.println("Failed.");
}
Breakdown
1
if (score >= 50)
Checks if the value of 'score' is 50 or higher.
2
else
Starts the block of code that runs if the 'if' condition was not met.