Simple-if Statement in Java

Card image cap

simple-if Statement ?

This statement is used for testing a condition and excuting a part of code based on the result of the condition.
The condition shuld be a boolean expression which evaluates to either true or false.
if(expression or condition)
}
..................
Statement;
}

The condition or test expression is evaluated.

If the result of the expression is true a bloack of statements will be executed.

If the result is false the program continues from the next statement after the if block.

Syntax :

 if (condition)
  {   .......
  	Statement;
      .......
  }
  
Card image cap
Card image cap

Example 1:



Output :

Number is positive.
This statement is always executed.
Card image cap

Example 2:



Output :

number is less than 100
Card image cap