java else-if code example
Example 1: if and in java
if(x == 1 && y == 2){
println("x = 1 and y = 2");
}
Example 2: else if java
else if statement is used to specify new condition if first condition is false.
Syntax:
if(condition1)
{
// execute if condition1 is true
}
else if (condition2)
{
// execute if condition2 is true
}
else if (condition3)
{
// execute if condition3 is true
}
else
{
// execute if conditions 1, 2 and 3 becomes false
}