if statement


The if statement is used when we want to execute some statements when the specified condition is true.

Note: curly braces { } are not required when if block contains only a single line to be execute.


Syntax:

if (condition)
{
    statements to be executed
}    

Example:

int a = 15;

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

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

Output:

a is less than 20