else statement


The else statement is used to execute the statements when the condition specified in if statement is false.


Syntax:

if (condition)
{
    statements to be executed
}
else
{
    statements to be executed
}

Example:

int a = 15;

if(a < 10)
{
    System.out.print(“a is less than 10”);
}

else
{
    System.out.print(“a is greater than 10”);
}

Output:

a is greater than 10