if…..else Statement
In an if...else statement, we have two blocks of code: the former block of code (inside the if statement) is executed if the condition evaluates to true, and the latter block of code (inside the else statement) is executed if the condition is false.
Syntax:
if (condition) {
// block of code
} else {
// block of code
}
Example:
public class JavaIf {
public static void main(String[] args) {
String name = "Mohan";
int Roll = 25;
if (name.equals("Mohan") && Roll == 26) {
System.out.println("Details of Mohan.");
} else {
System.out.println("Invalid details.");
}
}
}
Output:
Invalid details.