Conditional
statements are used to execute different code blocks based on different conditions.
If Statement
The
if statement
will only execute if the condition inside the parentheses is evaluated to true. The condition can include any of the comparison and logical operators.
int x = 1;
// ...
if (x == 1) {
System.out.println(x + " = 1");
}
To test for other conditions, the
if statement can be extended by any number of
else-if clauses. Each additional condition will only be tested if all previous conditions are false.
else if (x > 1) {
System.out.println(x + " > 1");
}
For handling ...