Java – If Then Statement

PREV     NEXT

The Java If Then Statement under the ‘if’ block are executed only when the condition evaluates to true.


Syntax Java If Then Statement :

If (condition)

{

//statements

}

Example:


Output:

a is greater than b
  • Here the value of a is greater than the value of b, thus the statement ‘a is greater than b is printed.
  • Deciding whether to execute the statement(s) or not, depends upon the condition specified. Hence it is called as decision making statement.

if statement’s condition should evaluate only to the boolean values ‘true’ or ‘false’. We can add more than one condition in the same if statement by using && or || operators.

PREV     NEXT




Like it? Please Spread the word!