If, If..else Statement in Java With Examples
If, If..else Statement in Java With Examples
if(condition){
Statement(s);
}
The statements gets executed only when the given condition is true. If the
condition is false then the statements inside if statement body are completely
ignored.
Example of if statement
public class IfStatementExample {
if(condition_2) {
Statement2(s);
}
}
Statement1 would execute if the condition_1 is true. Statement2 would only execute
if both the conditions( condition_1 and condition_2) are true.
Example of Nested if statement
public class NestedIfExample {